aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/initializers/migrations
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-23 14:39:52 +0200
committerChocobozzz <me@florianbigard.com>2018-04-23 14:39:52 +0200
commit9d3ef9fe052ed29bd67566754cb28662bd122234 (patch)
tree7b704dbc0b2c8b4ca18bef2409d640d0019c3d0a /server/initializers/migrations
parent2a2c19dfef7a9aa313c6ca0798f271c9a63449a9 (diff)
downloadPeerTube-9d3ef9fe052ed29bd67566754cb28662bd122234.tar.gz
PeerTube-9d3ef9fe052ed29bd67566754cb28662bd122234.tar.zst
PeerTube-9d3ef9fe052ed29bd67566754cb28662bd122234.zip
Use ISO 639 for languages
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r--server/initializers/migrations/0210-video-language.ts162
1 files changed, 162 insertions, 0 deletions
diff --git a/server/initializers/migrations/0210-video-language.ts b/server/initializers/migrations/0210-video-language.ts
new file mode 100644
index 000000000..b7ec90905
--- /dev/null
+++ b/server/initializers/migrations/0210-video-language.ts
@@ -0,0 +1,162 @@
1import * as Sequelize from 'sequelize'
2import { CONSTRAINTS_FIELDS } from '../index'
3
4async function up (utils: {
5 transaction: Sequelize.Transaction,
6 queryInterface: Sequelize.QueryInterface,
7 sequelize: Sequelize.Sequelize
8}): Promise<void> {
9
10 {
11 await utils.queryInterface.renameColumn('video', 'language', 'oldLanguage')
12 }
13
14 {
15 const data = {
16 type: Sequelize.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max),
17 allowNull: true,
18 defaultValue: null
19 }
20 await utils.queryInterface.addColumn('video', 'language', data)
21 }
22
23 {
24 const languages = [
25 {
26 oldLanguage: 1,
27 newLanguage: 'en'
28 },
29 {
30 oldLanguage: 2,
31 newLanguage: 'es'
32 },
33 {
34 oldLanguage: 3,
35 newLanguage: 'zh'
36 },
37 {
38 oldLanguage: 4,
39 newLanguage: 'hi'
40 },
41 {
42 oldLanguage: 5,
43 newLanguage: 'ar'
44 },
45 {
46 oldLanguage: 6,
47 newLanguage: 'pt'
48 },
49 {
50 oldLanguage: 7,
51 newLanguage: 'bn'
52 },
53 {
54 oldLanguage: 8,
55 newLanguage: 'ru'
56 },
57 {
58 oldLanguage: 9,
59 newLanguage: 'ja'
60 },
61 {
62 oldLanguage: 10,
63 newLanguage: 'pa'
64 },
65 {
66 oldLanguage: 11,
67 newLanguage: 'de'
68 },
69 {
70 oldLanguage: 12,
71 newLanguage: 'ko'
72 },
73 {
74 oldLanguage: 13,
75 newLanguage: 'fr'
76 },
77 {
78 oldLanguage: 14,
79 newLanguage: 'it'
80 },
81 {
82 oldLanguage: 1000,
83 newLanguage: 'sgn'
84 },
85 {
86 oldLanguage: 1001,
87 newLanguage: 'ase'
88 },
89 {
90 oldLanguage: 1002,
91 newLanguage: 'sdl'
92 },
93 {
94 oldLanguage: 1003,
95 newLanguage: 'bfi'
96 },
97 {
98 oldLanguage: 1004,
99 newLanguage: 'bzs'
100 },
101 {
102 oldLanguage: 1005,
103 newLanguage: 'csl'
104 },
105 {
106 oldLanguage: 1006,
107 newLanguage: 'cse'
108 },
109 {
110 oldLanguage: 1007,
111 newLanguage: 'dsl'
112 },
113 {
114 oldLanguage: 1008,
115 newLanguage: 'fsl'
116 },
117 {
118 oldLanguage: 1009,
119 newLanguage: 'gsg'
120 },
121 {
122 oldLanguage: 1010,
123 newLanguage: 'pks'
124 },
125 {
126 oldLanguage: 1011,
127 newLanguage: 'jsl'
128 },
129 {
130 oldLanguage: 1012,
131 newLanguage: 'sfs'
132 },
133 {
134 oldLanguage: 1013,
135 newLanguage: 'swl'
136 },
137 {
138 oldLanguage: 1014,
139 newLanguage: 'rsl'
140 }
141 ]
142
143 for (const language of languages) {
144 const query = 'UPDATE "video" SET "language" = \'' + language.newLanguage + '\' WHERE "oldLanguage" = ' + language.oldLanguage
145 await utils.sequelize.query(query)
146 }
147 }
148
149 {
150 await utils.queryInterface.removeColumn('video', 'oldLanguage')
151 }
152
153}
154
155function down (options) {
156 throw new Error('Not implemented.')
157}
158
159export {
160 up,
161 down
162}