Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add versions info to Project model #4526

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions forge/db/migrations/20240920-01-add-versions-to-project.js
Original file line number Diff line number Diff line change
@@ -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) => {
}
}
29 changes: 29 additions & 0 deletions forge/db/models/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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
Expand Down
Loading