Track offline record modify dates to help with sync processes
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-10-30 22:26:42 -05:00
parent 708c029079
commit 36ea67a9d6
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
12 changed files with 99 additions and 17 deletions

View File

@ -9,6 +9,7 @@ export interface ICodium {
UUID: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class Codium extends Model<ICodium> implements ICodium {
@ -20,13 +21,14 @@ export class Codium extends Model<ICodium> implements ICodium {
UUID: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'codiums';
}
public static getSchema() {
return '++id, Language, NodeId, PageId, code, UUID, needsServerUpdate, deleted';
return '++id, Language, NodeId, PageId, code, UUID, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -37,6 +39,7 @@ export class Codium extends Model<ICodium> implements ICodium {
UUID: string,
needsServerUpdate?: boolean,
deleted?: boolean,
offlineUpdatedAt?: string,
id?: number
) {
super();
@ -55,6 +58,10 @@ export class Codium extends Model<ICodium> implements ICodium {
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -78,6 +85,7 @@ export class Codium extends Model<ICodium> implements ICodium {
UUID: this.UUID,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -10,6 +10,7 @@ export interface IDatabase {
Active: boolean;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class Database extends Model<IDatabase> implements IDatabase {
@ -22,13 +23,14 @@ export class Database extends Model<IDatabase> implements IDatabase {
Active: boolean;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'databases';
}
public static getSchema() {
return '++id, Name, NodeId, PageId, ColumnIds, UUID, Active, needsServerUpdate, deleted';
return '++id, Name, NodeId, PageId, ColumnIds, UUID, Active, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -40,7 +42,8 @@ export class Database extends Model<IDatabase> implements IDatabase {
Active: boolean,
needsServerUpdate?: boolean,
deleted?: boolean,
id?: number
offlineUpdatedAt?: string,
id?: number,
) {
super();
@ -59,6 +62,10 @@ export class Database extends Model<IDatabase> implements IDatabase {
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -84,6 +91,7 @@ export class Database extends Model<IDatabase> implements IDatabase {
Active: this.Active,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -10,6 +10,7 @@ export interface IDatabaseColumn {
additionalData: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseColumn {
@ -22,13 +23,14 @@ export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseC
additionalData: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'databaseColumns';
}
public static getSchema() {
return '++id, headerName, field, DatabaseId, UUID, Type, additionalData, needsServerUpdate, deleted';
return '++id, headerName, field, DatabaseId, UUID, Type, additionalData, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -40,7 +42,8 @@ export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseC
additionalData: string,
needsServerUpdate?: boolean,
deleted?: boolean,
id?: number
offlineUpdatedAt?: string,
id?: number,
) {
super();
@ -59,6 +62,10 @@ export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseC
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -84,6 +91,7 @@ export class DatabaseColumn extends Model<IDatabaseColumn> implements IDatabaseC
additionalData: this.additionalData,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -7,6 +7,7 @@ export interface IDatabaseEntry {
UUID: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEntry {
@ -16,13 +17,14 @@ export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEnt
UUID: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'databaseEntries';
}
public static getSchema() {
return '++id, DatabaseId, RowDataJSON, UUID, needsServerUpdate, deleted';
return '++id, DatabaseId, RowDataJSON, UUID, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -31,7 +33,8 @@ export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEnt
UUID: string,
needsServerUpdate?: boolean,
deleted?: boolean,
id?: number
offlineUpdatedAt?: string,
id?: number,
) {
super();
@ -47,6 +50,10 @@ export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEnt
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -73,6 +80,7 @@ export class DatabaseEntry extends Model<IDatabaseEntry> implements IDatabaseEnt
UUID: this.UUID,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt })
};
}

View File

@ -9,6 +9,7 @@ export interface IFileGroup {
UUID: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class FileGroup extends Model<IFileGroup> implements IFileGroup {
@ -20,13 +21,14 @@ export class FileGroup extends Model<IFileGroup> implements IFileGroup {
UUID: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'fileGroups';
}
public static getSchema() {
return '++id, NodeId, PageId, FileIds, filesJSON, UUID, needsServerUpdate, deleted';
return '++id, NodeId, PageId, FileIds, filesJSON, UUID, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -37,7 +39,8 @@ export class FileGroup extends Model<IFileGroup> implements IFileGroup {
UUID: string,
needsServerUpdate?: boolean,
deleted?: boolean,
id?: number
offlineUpdatedAt?: string,
id?: number,
) {
super();
@ -55,6 +58,10 @@ export class FileGroup extends Model<IFileGroup> implements IFileGroup {
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -88,6 +95,7 @@ export class FileGroup extends Model<IFileGroup> implements IFileGroup {
UUID: this.UUID,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -5,6 +5,7 @@ export interface IKeyValue {
key: string;
value: string;
json: boolean;
offlineUpdatedAt?: string;
}
export class KeyValue extends Model<IKeyValue> implements IKeyValue {
@ -12,21 +13,27 @@ export class KeyValue extends Model<IKeyValue> implements IKeyValue {
key: string;
value: string;
json: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'keyValues';
}
public static getSchema() {
return '++id, key, value, json';
return '++id, key, value, json, offlineUpdatedAt';
}
constructor(key: string, value: string, json: boolean, id?: number) {
constructor(key: string, value: string, json: boolean, offlineUpdatedAt?: string, id?: number) {
super();
this.key = key;
this.value = value;
this.json = json;
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -56,6 +63,7 @@ export class KeyValue extends Model<IKeyValue> implements IKeyValue {
key: this.key,
value: this.value,
json: this.json,
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt })
};
}

View File

@ -12,6 +12,7 @@ export interface IMenuItem {
type?: string;
shared?: boolean;
needsServerUpdate?: boolean;
offlineUpdatedAt?: string;
}
export class MenuItem extends Model<IMenuItem> implements IMenuItem {
@ -25,13 +26,14 @@ export class MenuItem extends Model<IMenuItem> implements IMenuItem {
type?: string;
shared?: boolean;
needsServerUpdate?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'menuItems';
}
public static getSchema() {
return '++id, serverId, name, childIds, noDelete, noChildren, virtual, type, shared, needsServerUpdate';
return '++id, serverId, name, childIds, noDelete, noChildren, virtual, type, shared, needsServerUpdate, offlineUpdatedAt';
}
public static deflateTree(nodes: any[]): MenuItem[] {
@ -111,6 +113,7 @@ export class MenuItem extends Model<IMenuItem> implements IMenuItem {
type?: string,
shared?: boolean,
needsServerUpdate?: boolean,
offlineUpdatedAt?: string,
id?: number
) {
super();
@ -145,6 +148,10 @@ export class MenuItem extends Model<IMenuItem> implements IMenuItem {
this.needsServerUpdate = needsServerUpdate;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -166,6 +173,7 @@ export class MenuItem extends Model<IMenuItem> implements IMenuItem {
...(typeof this.type !== 'undefined' ? { type: this.type } : {}),
...(typeof this.shared !== 'undefined' ? { shared: this.shared } : {}),
...(typeof this.needsServerUpdate !== 'undefined' ? { needsServerUpdate: this.needsServerUpdate } : {}),
...(typeof this.offlineUpdatedAt !== 'undefined' ? { offlineUpdatedAt: this.offlineUpdatedAt } : {}),
};
}
}

View File

@ -4,26 +4,33 @@ export interface IMigration {
id?: number;
uuid: string;
applied: boolean;
offlineUpdatedAt?: string;
}
export class Migration extends Model<IMigration> implements IMigration {
id?: number;
uuid: string;
applied: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'migrations';
}
public static getSchema() {
return '++id, uuid, applied';
return '++id, uuid, applied, offlineUpdatedAt';
}
constructor(uuid: string, applied: boolean, id?: number) {
constructor(uuid: string, applied: boolean, offlineUpdatedAt?: string, id?: number) {
super();
this.uuid = uuid;
this.applied = applied;
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -34,6 +41,7 @@ export class Migration extends Model<IMigration> implements IMigration {
...(this.id ? { id: this.id } : {}),
uuid: this.uuid,
applied: this.applied,
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -43,6 +43,8 @@ export abstract class Model<InterfaceType> {
}
}
record.offlineUpdatedAt = String(new Date());
this.id = await this.getDatabase().put(record);
}
}

View File

@ -19,6 +19,7 @@ export interface IPage {
virtual: boolean;
needsServerUpdate?: 0 | 1;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class Page extends Model<IPage> implements IPage {
@ -40,6 +41,7 @@ export class Page extends Model<IPage> implements IPage {
virtual: boolean;
needsServerUpdate?: 0 | 1;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'pages';
@ -47,7 +49,7 @@ export class Page extends Model<IPage> implements IPage {
public static getSchema() {
// tslint:disable-next-line:max-line-length
return '++id, UUID, Name, OrgUserId, IsPublic, IsVisibleInMenu, ParentId, NodeIds, CreatedAt, UpdatedAt, Active, CreatedUserId, UpdateUserId, ChildPageIds, noDelete, virtual, needsServerUpdate, deleted';
return '++id, UUID, Name, OrgUserId, IsPublic, IsVisibleInMenu, ParentId, NodeIds, CreatedAt, UpdatedAt, Active, CreatedUserId, UpdateUserId, ChildPageIds, noDelete, virtual, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -68,6 +70,7 @@ export class Page extends Model<IPage> implements IPage {
virtual: boolean,
needsServerUpdate?: 0 | 1,
deleted?: boolean,
offlineUpdatedAt?: string,
id?: number
) {
super();
@ -96,6 +99,10 @@ export class Page extends Model<IPage> implements IPage {
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -141,6 +148,7 @@ export class Page extends Model<IPage> implements IPage {
virtual: this.virtual,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -12,6 +12,7 @@ export interface IPageNode {
UpdateUserId: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
}
export class PageNode extends Model<IPageNode> implements IPageNode {
@ -26,6 +27,7 @@ export class PageNode extends Model<IPageNode> implements IPageNode {
UpdateUserId: string;
needsServerUpdate?: boolean;
deleted?: boolean;
offlineUpdatedAt?: string;
public static getTableName() {
return 'pageNodes';
@ -33,7 +35,7 @@ export class PageNode extends Model<IPageNode> implements IPageNode {
public static getSchema() {
// tslint:disable-next-line:max-line-length
return '++id, UUID, Type, ValueJSON, PageId, CreatedAt, UpdatedAt, CreatedUserId, UpdateUserId, needsServerUpdate, deleted';
return '++id, UUID, Type, ValueJSON, PageId, CreatedAt, UpdatedAt, CreatedUserId, UpdateUserId, needsServerUpdate, deleted, offlineUpdatedAt';
}
constructor(
@ -47,6 +49,7 @@ export class PageNode extends Model<IPageNode> implements IPageNode {
UpdateUserId: string,
needsServerUpdate?: boolean,
deleted?: boolean,
offlineUpdatedAt?: string,
id?: number
) {
super();
@ -68,6 +71,10 @@ export class PageNode extends Model<IPageNode> implements IPageNode {
this.deleted = deleted;
}
if ( typeof offlineUpdatedAt !== 'undefined' ) {
this.offlineUpdatedAt = offlineUpdatedAt;
}
if ( id ) {
this.id = id;
}
@ -104,6 +111,7 @@ export class PageNode extends Model<IPageNode> implements IPageNode {
UpdateUserId: this.UpdateUserId,
...(typeof this.needsServerUpdate === 'undefined' ? {} : { needsServerUpdate: this.needsServerUpdate }),
...(typeof this.deleted === 'undefined' ? {} : { deleted: this.deleted }),
...(typeof this.offlineUpdatedAt === 'undefined' ? {} : { offlineUpdatedAt: this.offlineUpdatedAt }),
};
}

View File

@ -63,7 +63,7 @@ export class DatabaseService extends Dexie {
schema[ModelClass.getTableName()] = ModelClass.getSchema();
}
await this.version(14).stores(schema);
await this.version(15).stores(schema);
await this.open();
this.migrations = this.table('migrations');