adminizer 4.4.0-build.161 → 4.4.0-build.163
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
/**
|
|
3
|
+
* Creates all system model tables for Adminizer
|
|
4
|
+
* Tables: userap, groupap, mediamanagerap, mediamanagermetaap, mediamanagerassociationsap,
|
|
5
|
+
* notificationap, usernotificationap, navigationap, groupapuserap
|
|
6
|
+
*/
|
|
7
|
+
export declare function up(knex: Knex): Promise<void>;
|
|
8
|
+
export declare function down(knex: Knex): Promise<void>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates all system model tables for Adminizer
|
|
3
|
+
* Tables: userap, groupap, mediamanagerap, mediamanagermetaap, mediamanagerassociationsap,
|
|
4
|
+
* notificationap, usernotificationap, navigationap, groupapuserap
|
|
5
|
+
*/
|
|
6
|
+
export async function up(knex) {
|
|
7
|
+
// Helper to get the correct default timestamp based on database client
|
|
8
|
+
const getDefaultTimestamp = () => {
|
|
9
|
+
const client = knex.client.config.client;
|
|
10
|
+
if (client === 'pg' || client === 'postgresql') {
|
|
11
|
+
return knex.raw('CURRENT_TIMESTAMP');
|
|
12
|
+
}
|
|
13
|
+
else if (client === 'sqlite3') {
|
|
14
|
+
return knex.raw("(datetime('now'))");
|
|
15
|
+
}
|
|
16
|
+
else if (client === 'mysql' || client === 'mysql2') {
|
|
17
|
+
return knex.raw('CURRENT_TIMESTAMP');
|
|
18
|
+
}
|
|
19
|
+
return knex.fn.now();
|
|
20
|
+
};
|
|
21
|
+
// Helper to get UUID default based on database client
|
|
22
|
+
const getUuidDefault = () => {
|
|
23
|
+
const client = knex.client.config.client;
|
|
24
|
+
if (client === 'pg' || client === 'postgresql') {
|
|
25
|
+
return knex.raw('gen_random_uuid()');
|
|
26
|
+
}
|
|
27
|
+
else if (client === 'sqlite3') {
|
|
28
|
+
// SQLite doesn't have native UUID, will need to handle in application
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return knex.raw('UUID()');
|
|
32
|
+
};
|
|
33
|
+
const defaultTimestamp = getDefaultTimestamp();
|
|
34
|
+
const uuidDefault = getUuidDefault();
|
|
35
|
+
// userap
|
|
36
|
+
await knex.schema.createTable("userap", (table) => {
|
|
37
|
+
table.increments("id").primary().notNullable();
|
|
38
|
+
table.string("login").unique();
|
|
39
|
+
table.string("fullName");
|
|
40
|
+
table.string("email");
|
|
41
|
+
table.string("avatar");
|
|
42
|
+
table.string("passwordHashed");
|
|
43
|
+
table.string("timezone");
|
|
44
|
+
table.string("expires");
|
|
45
|
+
table.string("locale");
|
|
46
|
+
table.boolean("isDeleted");
|
|
47
|
+
table.boolean("isActive");
|
|
48
|
+
table.boolean("isAdministrator");
|
|
49
|
+
table.json("widgets");
|
|
50
|
+
table.boolean("isConfirmed");
|
|
51
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
52
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
53
|
+
});
|
|
54
|
+
// groupap
|
|
55
|
+
await knex.schema.createTable("groupap", (table) => {
|
|
56
|
+
table.increments("id").primary().notNullable();
|
|
57
|
+
table.string("name").unique();
|
|
58
|
+
table.string("description");
|
|
59
|
+
table.json("tokens");
|
|
60
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
61
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
62
|
+
});
|
|
63
|
+
// mediamanagerap (self-ref via parentId)
|
|
64
|
+
await knex.schema.createTable("mediamanagerap", (table) => {
|
|
65
|
+
if (uuidDefault) {
|
|
66
|
+
table.uuid("id").primary().notNullable().defaultTo(uuidDefault);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
table.uuid("id").primary().notNullable();
|
|
70
|
+
}
|
|
71
|
+
table.uuid("parentId").nullable().references("id").inTable("mediamanagerap").onDelete("SET NULL");
|
|
72
|
+
table.string("mimeType");
|
|
73
|
+
table.string("path");
|
|
74
|
+
table.integer("size");
|
|
75
|
+
table.string("group");
|
|
76
|
+
table.string("tag");
|
|
77
|
+
table.string("url");
|
|
78
|
+
table.string("filename");
|
|
79
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
80
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
81
|
+
});
|
|
82
|
+
// mediamanagermetaap (belongsTo mediamanagerap via parentId)
|
|
83
|
+
await knex.schema.createTable("mediamanagermetaap", (table) => {
|
|
84
|
+
if (uuidDefault) {
|
|
85
|
+
table.uuid("id").primary().notNullable().defaultTo(uuidDefault);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
table.uuid("id").primary().notNullable();
|
|
89
|
+
}
|
|
90
|
+
table.string("key");
|
|
91
|
+
table.json("value");
|
|
92
|
+
table.boolean("isPublic");
|
|
93
|
+
table.uuid("parentId").nullable().references("id").inTable("mediamanagerap").onDelete("SET NULL");
|
|
94
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
95
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
96
|
+
});
|
|
97
|
+
// mediamanagerassociationsap (belongsTo mediamanagerap via fileId)
|
|
98
|
+
await knex.schema.createTable("mediamanagerassociationsap", (table) => {
|
|
99
|
+
if (uuidDefault) {
|
|
100
|
+
table.uuid("id").primary().notNullable().defaultTo(uuidDefault);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
table.uuid("id").primary().notNullable();
|
|
104
|
+
}
|
|
105
|
+
table.string("mediaManagerId");
|
|
106
|
+
table.json("model");
|
|
107
|
+
table.json("modelId");
|
|
108
|
+
table.string("widgetName");
|
|
109
|
+
table.integer("sortOrder");
|
|
110
|
+
table.uuid("fileId").nullable().references("id").inTable("mediamanagerap").onDelete("SET NULL");
|
|
111
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
112
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
113
|
+
});
|
|
114
|
+
// notificationap
|
|
115
|
+
await knex.schema.createTable("notificationap", (table) => {
|
|
116
|
+
table.increments("id").primary().notNullable();
|
|
117
|
+
table.string("title");
|
|
118
|
+
table.string("message");
|
|
119
|
+
table.string("notificationClass");
|
|
120
|
+
table.string("channel");
|
|
121
|
+
table.json("metadata");
|
|
122
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
123
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
124
|
+
});
|
|
125
|
+
// usernotificationap (FK to notificationap via column notificationIdId)
|
|
126
|
+
await knex.schema.createTable("usernotificationap", (table) => {
|
|
127
|
+
table.increments("id").primary().notNullable();
|
|
128
|
+
table.integer("userId");
|
|
129
|
+
table.integer("notificationIdId").nullable().references("id").inTable("notificationap").onDelete("SET NULL");
|
|
130
|
+
table.boolean("read");
|
|
131
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
132
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
133
|
+
});
|
|
134
|
+
// navigationap
|
|
135
|
+
await knex.schema.createTable("navigationap", (table) => {
|
|
136
|
+
table.increments("id").primary().notNullable();
|
|
137
|
+
table.string("label").unique();
|
|
138
|
+
table.json("tree");
|
|
139
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
140
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
141
|
+
});
|
|
142
|
+
// M:N join: GroupAP <-> UserAP via "groupapuserap"
|
|
143
|
+
await knex.schema.createTable("groupapuserap", (table) => {
|
|
144
|
+
table.integer("UserAPId").notNullable().references("id").inTable("userap").onDelete("CASCADE");
|
|
145
|
+
table.integer("GroupAPId").notNullable().references("id").inTable("groupap").onDelete("CASCADE");
|
|
146
|
+
table.timestamp("createdAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
147
|
+
table.timestamp("updatedAt", { useTz: false }).notNullable().defaultTo(defaultTimestamp);
|
|
148
|
+
table.primary(["UserAPId", "GroupAPId"]);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
export async function down(knex) {
|
|
152
|
+
await knex.schema.dropTableIfExists("groupapuserap");
|
|
153
|
+
await knex.schema.dropTableIfExists("usernotificationap");
|
|
154
|
+
await knex.schema.dropTableIfExists("mediamanagermetaap");
|
|
155
|
+
await knex.schema.dropTableIfExists("mediamanagerassociationsap");
|
|
156
|
+
await knex.schema.dropTableIfExists("mediamanagerap");
|
|
157
|
+
await knex.schema.dropTableIfExists("navigationap");
|
|
158
|
+
await knex.schema.dropTableIfExists("notificationap");
|
|
159
|
+
await knex.schema.dropTableIfExists("groupap");
|
|
160
|
+
await knex.schema.dropTableIfExists("userap");
|
|
161
|
+
}
|