Track database versioning & include in Node version data
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3bef5f3423
commit
9398c827ed
@ -37,7 +37,7 @@ class FormDatabase extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.save()
|
await db.version_save(`Added to page "${page.Name}"`, req.user.id)
|
||||||
|
|
||||||
req.user.allow(`database:${db.UUID}`);
|
req.user.allow(`database:${db.UUID}`);
|
||||||
await req.user.save()
|
await req.user.save()
|
||||||
@ -124,8 +124,13 @@ class FormDatabase extends Controller {
|
|||||||
if ( !db ) return res.status(404).message('Database not found with that ID.').api({})
|
if ( !db ) return res.status(404).message('Database not found with that ID.').api({})
|
||||||
// if ( !db.accessible_by(req.user, 'update') ) return req.security.deny()
|
// if ( !db.accessible_by(req.user, 'update') ) return req.security.deny()
|
||||||
|
|
||||||
|
if ( req.body.Name !== db.Name ) {
|
||||||
db.Name = req.body.Name
|
db.Name = req.body.Name
|
||||||
|
await db.version_save(`Changed database name to "${req.body.Name}"`, req.user.id)
|
||||||
|
} else {
|
||||||
await db.save()
|
await db.save()
|
||||||
|
}
|
||||||
|
|
||||||
return res.api(db)
|
return res.api(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,8 +192,14 @@ class FormDatabase extends Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.ColumnIds = update_columns.map(x => x.UUID)
|
const new_cols = update_columns.map(x => x.UUID)
|
||||||
|
const no_updates = (new_cols.length === db.ColumnIds.length) && (new_cols.every(val => db.ColumnIds.includes(val)));
|
||||||
|
if ( !no_updates ) {
|
||||||
|
db.ColumnIds = new_cols
|
||||||
|
await db.version_save('Updated columns', req.user.id)
|
||||||
|
} else {
|
||||||
await db.save()
|
await db.save()
|
||||||
|
}
|
||||||
|
|
||||||
return res.api(update_columns)
|
return res.api(update_columns)
|
||||||
}
|
}
|
||||||
@ -248,6 +259,7 @@ class FormDatabase extends Controller {
|
|||||||
new_recs.push(dbe)
|
new_recs.push(dbe)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await db.version_save('Updated data', req.user.id)
|
||||||
return res.api(await this._set_indices(db, new_recs))
|
return res.api(await this._set_indices(db, new_recs))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,6 +281,7 @@ class FormDatabase extends Controller {
|
|||||||
// if ( !db.accessible_by(req.user) ) return req.security.deny()
|
// if ( !db.accessible_by(req.user) ) return req.security.deny()
|
||||||
|
|
||||||
await DBEntry.deleteMany({DatabaseId: db.UUID})
|
await DBEntry.deleteMany({DatabaseId: db.UUID})
|
||||||
|
await db.version_save('Deleted', req.user.id)
|
||||||
await db.delete()
|
await db.delete()
|
||||||
return res.api({})
|
return res.api({})
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,12 @@ class Node extends VersionedModel {
|
|||||||
if ( group ) {
|
if ( group ) {
|
||||||
data.associated_type_version_num = group.version_num
|
data.associated_type_version_num = group.version_num
|
||||||
}
|
}
|
||||||
|
} else if ( this.Type === 'database_ref' && this.Value?.Value ) {
|
||||||
|
const Database = this.models.get('api:db:Database')
|
||||||
|
const db = await Database.findOne({ Active: true, UUID: this.Value?.Value })
|
||||||
|
if ( db ) {
|
||||||
|
data.associated_type_version_num = db.version_num
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const Model = require('flitter-orm/src/model/Model')
|
const VersionedModel = require('../../VersionedModel')
|
||||||
const uuid = require('uuid/v4')
|
const uuid = require('uuid/v4')
|
||||||
const ColumnDef = require('./ColumnDef.model')
|
const ColumnDef = require('./ColumnDef.model')
|
||||||
const Page = require('../Page.model')
|
const Page = require('../Page.model')
|
||||||
@ -10,10 +10,11 @@ const ActiveScope = require('../../scopes/Active.scope')
|
|||||||
* -------------------------------------------------------------
|
* -------------------------------------------------------------
|
||||||
* Put some description here!
|
* Put some description here!
|
||||||
*/
|
*/
|
||||||
class Database extends Model {
|
class Database extends VersionedModel {
|
||||||
static get schema() {
|
static get schema() {
|
||||||
// Return a flitter-orm schema here.
|
// Return a flitter-orm schema here.
|
||||||
return {
|
return {
|
||||||
|
...super.schema,
|
||||||
Name: String,
|
Name: String,
|
||||||
NodeId: String,
|
NodeId: String,
|
||||||
PageId: String,
|
PageId: String,
|
||||||
@ -52,7 +53,7 @@ class Database extends Model {
|
|||||||
|
|
||||||
async delete() {
|
async delete() {
|
||||||
this.Active = false
|
this.Active = false
|
||||||
await this.save()
|
await this.version_save(`Deleted`)
|
||||||
}
|
}
|
||||||
|
|
||||||
to_api_object() {
|
to_api_object() {
|
||||||
@ -61,6 +62,8 @@ class Database extends Model {
|
|||||||
uuid: this.UUID,
|
uuid: this.UUID,
|
||||||
page_id: this.PageId,
|
page_id: this.PageId,
|
||||||
column_ids: this.ColumnIds,
|
column_ids: this.ColumnIds,
|
||||||
|
version_num: this.version_num,
|
||||||
|
version_message: this.version_message,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user