diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-03 15:08:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-03 15:08:36 +0200 |
commit | c795e19663a93c24908a7318975f820bac63164f (patch) | |
tree | 149a303be38eedf5aa5a0ec02938f67c75a267fe /server/initializers | |
parent | fd59208e8ccd796f9ad7e35db82d0c33acfcb92c (diff) | |
download | PeerTube-c795e19663a93c24908a7318975f820bac63164f.tar.gz PeerTube-c795e19663a93c24908a7318975f820bac63164f.tar.zst PeerTube-c795e19663a93c24908a7318975f820bac63164f.zip |
Automatically rebuild native modules on ABI change
Diffstat (limited to 'server/initializers')
-rw-r--r-- | server/initializers/constants.ts | 2 | ||||
-rw-r--r-- | server/initializers/installer.ts | 7 | ||||
-rw-r--r-- | server/initializers/migrations/0725-node-version.ts | 66 |
3 files changed, 72 insertions, 3 deletions
diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 99ae64f8d..8165a289d 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts | |||
@@ -24,7 +24,7 @@ import { CONFIG, registerConfigChangedHandler } from './config' | |||
24 | 24 | ||
25 | // --------------------------------------------------------------------------- | 25 | // --------------------------------------------------------------------------- |
26 | 26 | ||
27 | const LAST_MIGRATION_VERSION = 720 | 27 | const LAST_MIGRATION_VERSION = 725 |
28 | 28 | ||
29 | // --------------------------------------------------------------------------- | 29 | // --------------------------------------------------------------------------- |
30 | 30 | ||
diff --git a/server/initializers/installer.ts b/server/initializers/installer.ts index 7d5919459..b02be9567 100644 --- a/server/initializers/installer.ts +++ b/server/initializers/installer.ts | |||
@@ -1,6 +1,8 @@ | |||
1 | import { ensureDir, readdir, remove } from 'fs-extra' | 1 | import { ensureDir, readdir, remove } from 'fs-extra' |
2 | import passwordGenerator from 'password-generator' | 2 | import passwordGenerator from 'password-generator' |
3 | import { join } from 'path' | 3 | import { join } from 'path' |
4 | import { isTestOrDevInstance } from '@server/helpers/core-utils' | ||
5 | import { getNodeABIVersion } from '@server/helpers/version' | ||
4 | import { UserRole } from '@shared/models' | 6 | import { UserRole } from '@shared/models' |
5 | import { logger } from '../helpers/logger' | 7 | import { logger } from '../helpers/logger' |
6 | import { buildUser, createApplicationActor, createUserAccountAndChannelAndPlaylist } from '../lib/user' | 8 | import { buildUser, createApplicationActor, createUserAccountAndChannelAndPlaylist } from '../lib/user' |
@@ -10,7 +12,6 @@ import { applicationExist, clientsExist, usersExist } from './checker-after-init | |||
10 | import { CONFIG } from './config' | 12 | import { CONFIG } from './config' |
11 | import { FILES_CACHE, HLS_STREAMING_PLAYLIST_DIRECTORY, LAST_MIGRATION_VERSION, RESUMABLE_UPLOAD_DIRECTORY } from './constants' | 13 | import { FILES_CACHE, HLS_STREAMING_PLAYLIST_DIRECTORY, LAST_MIGRATION_VERSION, RESUMABLE_UPLOAD_DIRECTORY } from './constants' |
12 | import { sequelizeTypescript } from './database' | 14 | import { sequelizeTypescript } from './database' |
13 | import { isTestOrDevInstance } from '@server/helpers/core-utils' | ||
14 | 15 | ||
15 | async function installApplication () { | 16 | async function installApplication () { |
16 | try { | 17 | try { |
@@ -175,7 +176,9 @@ async function createApplicationIfNotExist () { | |||
175 | logger.info('Creating application account.') | 176 | logger.info('Creating application account.') |
176 | 177 | ||
177 | const application = await ApplicationModel.create({ | 178 | const application = await ApplicationModel.create({ |
178 | migrationVersion: LAST_MIGRATION_VERSION | 179 | migrationVersion: LAST_MIGRATION_VERSION, |
180 | nodeVersion: process.version, | ||
181 | nodeABIVersion: getNodeABIVersion() | ||
179 | }) | 182 | }) |
180 | 183 | ||
181 | return createApplicationActor(application.id) | 184 | return createApplicationActor(application.id) |
diff --git a/server/initializers/migrations/0725-node-version.ts b/server/initializers/migrations/0725-node-version.ts new file mode 100644 index 000000000..d8b9cc750 --- /dev/null +++ b/server/initializers/migrations/0725-node-version.ts | |||
@@ -0,0 +1,66 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | |||
3 | async function up (utils: { | ||
4 | transaction: Sequelize.Transaction | ||
5 | queryInterface: Sequelize.QueryInterface | ||
6 | sequelize: Sequelize.Sequelize | ||
7 | db: any | ||
8 | }): Promise<void> { | ||
9 | const { transaction } = utils | ||
10 | |||
11 | { | ||
12 | const data = { | ||
13 | type: Sequelize.STRING, | ||
14 | defaultValue: null, | ||
15 | allowNull: true | ||
16 | } | ||
17 | await utils.queryInterface.addColumn('application', 'nodeVersion', data, { transaction }) | ||
18 | } | ||
19 | |||
20 | { | ||
21 | const data = { | ||
22 | type: Sequelize.STRING, | ||
23 | defaultValue: null, | ||
24 | allowNull: true | ||
25 | } | ||
26 | await utils.queryInterface.addColumn('application', 'nodeABIVersion', data, { transaction }) | ||
27 | } | ||
28 | |||
29 | { | ||
30 | const query = `UPDATE "application" SET "nodeVersion" = '${process.version}'` | ||
31 | await utils.sequelize.query(query, { transaction }) | ||
32 | } | ||
33 | |||
34 | { | ||
35 | const nodeABIVersion = parseInt(process.versions.modules) | ||
36 | const query = `UPDATE "application" SET "nodeABIVersion" = ${nodeABIVersion}` | ||
37 | await utils.sequelize.query(query, { transaction }) | ||
38 | } | ||
39 | |||
40 | { | ||
41 | const data = { | ||
42 | type: Sequelize.STRING, | ||
43 | defaultValue: null, | ||
44 | allowNull: false | ||
45 | } | ||
46 | await utils.queryInterface.changeColumn('application', 'nodeVersion', data, { transaction }) | ||
47 | } | ||
48 | |||
49 | { | ||
50 | const data = { | ||
51 | type: Sequelize.STRING, | ||
52 | defaultValue: null, | ||
53 | allowNull: false | ||
54 | } | ||
55 | await utils.queryInterface.changeColumn('application', 'nodeABIVersion', data, { transaction }) | ||
56 | } | ||
57 | } | ||
58 | |||
59 | function down (options) { | ||
60 | throw new Error('Not implemented.') | ||
61 | } | ||
62 | |||
63 | export { | ||
64 | up, | ||
65 | down | ||
66 | } | ||