diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-12-25 09:44:57 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-12-25 09:44:57 +0100 |
commit | b769007f733769d3afe2d29a3eb23e2e7693f301 (patch) | |
tree | 3816d542e907f298d08338129e0f6b9ca0df8fbb /server/models | |
parent | dd6019932efd6ae3b790bf024bc0cd74162e4517 (diff) | |
download | PeerTube-b769007f733769d3afe2d29a3eb23e2e7693f301.tar.gz PeerTube-b769007f733769d3afe2d29a3eb23e2e7693f301.tar.zst PeerTube-b769007f733769d3afe2d29a3eb23e2e7693f301.zip |
Update migrations code
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/application.js | 26 | ||||
-rw-r--r-- | server/models/video.js | 7 |
2 files changed, 24 insertions, 9 deletions
diff --git a/server/models/application.js b/server/models/application.js index ec1d7b122..4114ed76d 100644 --- a/server/models/application.js +++ b/server/models/application.js | |||
@@ -1,15 +1,15 @@ | |||
1 | module.exports = function (sequelize, DataTypes) { | 1 | module.exports = function (sequelize, DataTypes) { |
2 | const Application = sequelize.define('Application', | 2 | const Application = sequelize.define('Application', |
3 | { | 3 | { |
4 | sqlSchemaVersion: { | 4 | migrationVersion: { |
5 | type: DataTypes.INTEGER, | 5 | type: DataTypes.INTEGER, |
6 | defaultValue: 0 | 6 | defaultValue: 0 |
7 | } | 7 | } |
8 | }, | 8 | }, |
9 | { | 9 | { |
10 | classMethods: { | 10 | classMethods: { |
11 | loadSqlSchemaVersion, | 11 | loadMigrationVersion, |
12 | updateSqlSchemaVersion | 12 | updateMigrationVersion |
13 | } | 13 | } |
14 | } | 14 | } |
15 | ) | 15 | ) |
@@ -19,18 +19,28 @@ module.exports = function (sequelize, DataTypes) { | |||
19 | 19 | ||
20 | // --------------------------------------------------------------------------- | 20 | // --------------------------------------------------------------------------- |
21 | 21 | ||
22 | function loadSqlSchemaVersion (callback) { | 22 | function loadMigrationVersion (callback) { |
23 | const query = { | 23 | const query = { |
24 | attributes: [ 'sqlSchemaVersion' ] | 24 | attributes: [ 'migrationVersion' ] |
25 | } | 25 | } |
26 | 26 | ||
27 | return this.findOne(query).asCallback(function (err, data) { | 27 | return this.findOne(query).asCallback(function (err, data) { |
28 | const version = data ? data.sqlSchemaVersion : 0 | 28 | const version = data ? data.migrationVersion : 0 |
29 | 29 | ||
30 | return callback(err, version) | 30 | return callback(err, version) |
31 | }) | 31 | }) |
32 | } | 32 | } |
33 | 33 | ||
34 | function updateSqlSchemaVersion (newVersion, callback) { | 34 | function updateMigrationVersion (newVersion, transaction, callback) { |
35 | return this.update({ sqlSchemaVersion: newVersion }).asCallback(callback) | 35 | const options = { |
36 | where: {} | ||
37 | } | ||
38 | |||
39 | if (!callback) { | ||
40 | transaction = callback | ||
41 | } else { | ||
42 | options.transaction = transaction | ||
43 | } | ||
44 | |||
45 | return this.update({ migrationVersion: newVersion }, options).asCallback(callback) | ||
36 | } | 46 | } |
diff --git a/server/models/video.js b/server/models/video.js index 0023a24e1..af05a861f 100644 --- a/server/models/video.js +++ b/server/models/video.js | |||
@@ -16,7 +16,7 @@ const modelUtils = require('./utils') | |||
16 | // --------------------------------------------------------------------------- | 16 | // --------------------------------------------------------------------------- |
17 | 17 | ||
18 | module.exports = function (sequelize, DataTypes) { | 18 | module.exports = function (sequelize, DataTypes) { |
19 | // TODO: add indexes on searchable columns | 19 | // TODO: add indexes on searchable columns |
20 | const Video = sequelize.define('Video', | 20 | const Video = sequelize.define('Video', |
21 | { | 21 | { |
22 | id: { | 22 | id: { |
@@ -50,6 +50,7 @@ module.exports = function (sequelize, DataTypes) { | |||
50 | 50 | ||
51 | generateThumbnailFromBase64, | 51 | generateThumbnailFromBase64, |
52 | getDurationFromFile, | 52 | getDurationFromFile, |
53 | list, | ||
53 | listForApi, | 54 | listForApi, |
54 | listByHostAndRemoteId, | 55 | listByHostAndRemoteId, |
55 | listOwnedAndPopulateAuthorAndTags, | 56 | listOwnedAndPopulateAuthorAndTags, |
@@ -310,6 +311,10 @@ function getDurationFromFile (videoPath, callback) { | |||
310 | }) | 311 | }) |
311 | } | 312 | } |
312 | 313 | ||
314 | function list (callback) { | ||
315 | return this.find().asCallback() | ||
316 | } | ||
317 | |||
313 | function listForApi (start, count, sort, callback) { | 318 | function listForApi (start, count, sort, callback) { |
314 | const query = { | 319 | const query = { |
315 | offset: start, | 320 | offset: start, |