From 9d3ef9fe052ed29bd67566754cb28662bd122234 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 Apr 2018 14:39:52 +0200 Subject: Use ISO 639 for languages --- .../initializers/migrations/0210-video-language.ts | 162 +++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 server/initializers/migrations/0210-video-language.ts (limited to 'server/initializers/migrations/0210-video-language.ts') 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 @@ +import * as Sequelize from 'sequelize' +import { CONSTRAINTS_FIELDS } from '../index' + +async function up (utils: { + transaction: Sequelize.Transaction, + queryInterface: Sequelize.QueryInterface, + sequelize: Sequelize.Sequelize +}): Promise { + + { + await utils.queryInterface.renameColumn('video', 'language', 'oldLanguage') + } + + { + const data = { + type: Sequelize.STRING(CONSTRAINTS_FIELDS.VIDEOS.LANGUAGE.max), + allowNull: true, + defaultValue: null + } + await utils.queryInterface.addColumn('video', 'language', data) + } + + { + const languages = [ + { + oldLanguage: 1, + newLanguage: 'en' + }, + { + oldLanguage: 2, + newLanguage: 'es' + }, + { + oldLanguage: 3, + newLanguage: 'zh' + }, + { + oldLanguage: 4, + newLanguage: 'hi' + }, + { + oldLanguage: 5, + newLanguage: 'ar' + }, + { + oldLanguage: 6, + newLanguage: 'pt' + }, + { + oldLanguage: 7, + newLanguage: 'bn' + }, + { + oldLanguage: 8, + newLanguage: 'ru' + }, + { + oldLanguage: 9, + newLanguage: 'ja' + }, + { + oldLanguage: 10, + newLanguage: 'pa' + }, + { + oldLanguage: 11, + newLanguage: 'de' + }, + { + oldLanguage: 12, + newLanguage: 'ko' + }, + { + oldLanguage: 13, + newLanguage: 'fr' + }, + { + oldLanguage: 14, + newLanguage: 'it' + }, + { + oldLanguage: 1000, + newLanguage: 'sgn' + }, + { + oldLanguage: 1001, + newLanguage: 'ase' + }, + { + oldLanguage: 1002, + newLanguage: 'sdl' + }, + { + oldLanguage: 1003, + newLanguage: 'bfi' + }, + { + oldLanguage: 1004, + newLanguage: 'bzs' + }, + { + oldLanguage: 1005, + newLanguage: 'csl' + }, + { + oldLanguage: 1006, + newLanguage: 'cse' + }, + { + oldLanguage: 1007, + newLanguage: 'dsl' + }, + { + oldLanguage: 1008, + newLanguage: 'fsl' + }, + { + oldLanguage: 1009, + newLanguage: 'gsg' + }, + { + oldLanguage: 1010, + newLanguage: 'pks' + }, + { + oldLanguage: 1011, + newLanguage: 'jsl' + }, + { + oldLanguage: 1012, + newLanguage: 'sfs' + }, + { + oldLanguage: 1013, + newLanguage: 'swl' + }, + { + oldLanguage: 1014, + newLanguage: 'rsl' + } + ] + + for (const language of languages) { + const query = 'UPDATE "video" SET "language" = \'' + language.newLanguage + '\' WHERE "oldLanguage" = ' + language.oldLanguage + await utils.sequelize.query(query) + } + } + + { + await utils.queryInterface.removeColumn('video', 'oldLanguage') + } + +} + +function down (options) { + throw new Error('Not implemented.') +} + +export { + up, + down +} -- cgit v1.2.3