diff --git a/forge/db/migrations/20240920-01-add-versions-to-project.js b/forge/db/migrations/20240920-01-add-versions-to-project.js new file mode 100644 index 0000000000..dde0540e03 --- /dev/null +++ b/forge/db/migrations/20240920-01-add-versions-to-project.js @@ -0,0 +1,19 @@ +/** + * Add versions to Project table + */ +const { DataTypes } = require('sequelize') + +module.exports = { + /** + * upgrade database + * @param {QueryInterface} context Sequelize.QueryInterface + */ + up: async (context) => { + await context.addColumn('Projects', 'versions', { + type: DataTypes.TEXT, + defaultValue: null + }) + }, + down: async (context) => { + } +} diff --git a/forge/db/models/Project.js b/forge/db/models/Project.js index 0b1992c4e5..af1ce44b72 100644 --- a/forge/db/models/Project.js +++ b/forge/db/models/Project.js @@ -88,6 +88,20 @@ module.exports = { get () { return this.getDataValue('safeName') || this.getDataValue('name')?.toLowerCase() } + }, + versions: { + type: DataTypes.TEXT, + get () { + const rawValue = this.getDataValue('versions') + return rawValue ? JSON.parse(rawValue) : {} + }, + set (value) { + if (Object.keys(value).length === 0) { + this.setDataValue('versions', null) + return + } + this.setDataValue('versions', JSON.stringify(value)) + } } }, indexes: [ @@ -289,6 +303,21 @@ module.exports = { } } else { result.meta = await app.containers.details(this) || { state: 'unknown' } + if (result.meta.versions) { + const currentVersionInfo = { ...this.versions } + let changed = false + for (const [key, value] of Object.entries(result.meta.versions)) { + currentVersionInfo[key] = currentVersionInfo[key] || {} + if (currentVersionInfo[key].current !== value) { + currentVersionInfo[key].current = value + changed = true + } + } + if (changed) { + this.versions = currentVersionInfo + await this.save() + } + } } result.meta.isDeploying = isDeploying