@nymphjs/driver-postgresql 1.0.0-beta.106 → 1.0.0-beta.107
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.
- package/CHANGELOG.md +7 -0
- package/dist/PostgreSQLDriver.d.ts +12 -2
- package/dist/PostgreSQLDriver.js +171 -55
- package/dist/PostgreSQLDriver.js.map +1 -1
- package/dist/PostgreSQLDriver.test.js +3 -0
- package/dist/PostgreSQLDriver.test.js.map +1 -1
- package/package.json +13 -12
- package/src/PostgreSQLDriver.test.ts +4 -0
- package/src/PostgreSQLDriver.ts +340 -70
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.0.0-beta.107](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.106...v1.0.0-beta.107) (2026-02-13)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- move tilmeld fields into columns in entities tables ([5f46048](https://github.com/sciactive/nymphjs/commit/5f46048c3e04839ca9a8b81f71a950b9086d0a41))
|
|
11
|
+
- update packages and fix all new issues ([0e9d17c](https://github.com/sciactive/nymphjs/commit/0e9d17c6e2db12c11bdfb559031719c1b52b5fa1))
|
|
12
|
+
|
|
6
13
|
# [1.0.0-beta.106](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.105...v1.0.0-beta.106) (2025-12-05)
|
|
7
14
|
|
|
8
15
|
### Bug Fixes
|
|
@@ -53,6 +53,8 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
53
53
|
*/
|
|
54
54
|
isConnected(): boolean;
|
|
55
55
|
private createEntitiesTable;
|
|
56
|
+
private addTilmeldColumnsAndIndexes;
|
|
57
|
+
private createEntitiesTilmeldIndexes;
|
|
56
58
|
private createDataTable;
|
|
57
59
|
private createReferencesTable;
|
|
58
60
|
private createTokensTable;
|
|
@@ -130,6 +132,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
130
132
|
sdata: SerializedEntityData;
|
|
131
133
|
etype: string;
|
|
132
134
|
}): Promise<void>;
|
|
135
|
+
importEntityTilmeldAC(entity: {
|
|
136
|
+
guid: string;
|
|
137
|
+
cdate: number;
|
|
138
|
+
mdate: number;
|
|
139
|
+
tags: string[];
|
|
140
|
+
sdata: SerializedEntityData;
|
|
141
|
+
etype: string;
|
|
142
|
+
}): Promise<void>;
|
|
133
143
|
private importEntityInternal;
|
|
134
144
|
importUID({ name, value }: {
|
|
135
145
|
name: string;
|
|
@@ -142,7 +152,7 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
142
152
|
setUID(name: string, curUid: number): Promise<boolean>;
|
|
143
153
|
protected internalTransaction(name: string): Promise<PostgreSQLDriverTransaction>;
|
|
144
154
|
startTransaction(name: string): Promise<import("@nymphjs/nymph").Nymph>;
|
|
145
|
-
needsMigration(): Promise<'json' | 'tokens' | false>;
|
|
146
|
-
liveMigration(
|
|
155
|
+
needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
|
|
156
|
+
liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns'): Promise<void>;
|
|
147
157
|
}
|
|
148
158
|
export {};
|
package/dist/PostgreSQLDriver.js
CHANGED
|
@@ -171,6 +171,14 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
171
171
|
"tags" TEXT[],
|
|
172
172
|
"cdate" DOUBLE PRECISION NOT NULL,
|
|
173
173
|
"mdate" DOUBLE PRECISION NOT NULL,
|
|
174
|
+
"user" BYTEA,
|
|
175
|
+
"group" BYTEA,
|
|
176
|
+
"acUser" SMALLINT,
|
|
177
|
+
"acGroup" SMALLINT,
|
|
178
|
+
"acOther" SMALLINT,
|
|
179
|
+
"acRead" BYTEA[],
|
|
180
|
+
"acWrite" BYTEA[],
|
|
181
|
+
"acFull" BYTEA[],
|
|
174
182
|
PRIMARY KEY ("guid")
|
|
175
183
|
) WITH ( OIDS=FALSE );`, { connection });
|
|
176
184
|
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} OWNER TO ${PostgreSQLDriver.escape(this.config.user)};`, { connection });
|
|
@@ -180,8 +188,38 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
180
188
|
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_mdate`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("mdate");`, { connection });
|
|
181
189
|
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_tags`)};`, { connection });
|
|
182
190
|
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_tags`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING gin ("tags");`, { connection });
|
|
191
|
+
await this.createEntitiesTilmeldIndexes(etype, connection);
|
|
183
192
|
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} SET ( autovacuum_vacuum_scale_factor = 0.05, autovacuum_analyze_scale_factor = 0.05 );`, { connection });
|
|
184
193
|
}
|
|
194
|
+
async addTilmeldColumnsAndIndexes(etype, connection) {
|
|
195
|
+
await this.queryRun(`ALTER TABLE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ADD COLUMN IF NOT EXISTS "user" BYTEA,
|
|
196
|
+
ADD COLUMN IF NOT EXISTS "group" BYTEA,
|
|
197
|
+
ADD COLUMN IF NOT EXISTS "acUser" SMALLINT,
|
|
198
|
+
ADD COLUMN IF NOT EXISTS "acGroup" SMALLINT,
|
|
199
|
+
ADD COLUMN IF NOT EXISTS "acOther" SMALLINT,
|
|
200
|
+
ADD COLUMN IF NOT EXISTS "acRead" BYTEA[],
|
|
201
|
+
ADD COLUMN IF NOT EXISTS "acWrite" BYTEA[],
|
|
202
|
+
ADD COLUMN IF NOT EXISTS "acFull" BYTEA[];`);
|
|
203
|
+
await this.createEntitiesTilmeldIndexes(etype, connection);
|
|
204
|
+
}
|
|
205
|
+
async createEntitiesTilmeldIndexes(etype, connection) {
|
|
206
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_user_acUser`)};`, { connection });
|
|
207
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_user_acUser`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("user", "acUser");`, { connection });
|
|
208
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_group_acGroup`)};`, { connection });
|
|
209
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_group_acGroup`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("group", "acGroup");`, { connection });
|
|
210
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acUser`)};`, { connection });
|
|
211
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acUser`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("acUser");`, { connection });
|
|
212
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acGroup`)};`, { connection });
|
|
213
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acGroup`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("acGroup");`, { connection });
|
|
214
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acOther`)};`, { connection });
|
|
215
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acOther`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING btree ("acOther");`, { connection });
|
|
216
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acRead`)};`, { connection });
|
|
217
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acRead`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING gin ("acRead");`, { connection });
|
|
218
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acWrite`)};`, { connection });
|
|
219
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acWrite`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING gin ("acWrite");`, { connection });
|
|
220
|
+
await this.queryRun(`DROP INDEX IF EXISTS ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acFull`)};`, { connection });
|
|
221
|
+
await this.queryRun(`CREATE INDEX ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}_id_acFull`)} ON ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} USING gin ("acFull");`, { connection });
|
|
222
|
+
}
|
|
185
223
|
async createDataTable(etype, connection) {
|
|
186
224
|
// Create the data table.
|
|
187
225
|
await this.queryRun(`CREATE TABLE IF NOT EXISTS ${PostgreSQLDriver.escape(`${this.prefix}data_${etype}`)} (
|
|
@@ -1850,15 +1888,18 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1850
1888
|
return result?.cur_uid == null ? null : Number(result.cur_uid);
|
|
1851
1889
|
}
|
|
1852
1890
|
async importEntity(entity) {
|
|
1853
|
-
return await this.importEntityInternal(entity
|
|
1891
|
+
return await this.importEntityInternal(entity);
|
|
1854
1892
|
}
|
|
1855
1893
|
async importEntityTokens(entity) {
|
|
1856
|
-
return await this.importEntityInternal(entity,
|
|
1894
|
+
return await this.importEntityInternal(entity, { only: 'tokens' });
|
|
1895
|
+
}
|
|
1896
|
+
async importEntityTilmeldAC(entity) {
|
|
1897
|
+
return await this.importEntityInternal(entity, { only: 'tilmeldAC' });
|
|
1857
1898
|
}
|
|
1858
|
-
async importEntityInternal({ guid, cdate, mdate, tags, sdata, etype, },
|
|
1899
|
+
async importEntityInternal({ guid, cdate, mdate, tags, sdata, etype, }, { only = undefined } = {}) {
|
|
1859
1900
|
try {
|
|
1860
1901
|
let promises = [];
|
|
1861
|
-
if (
|
|
1902
|
+
if (only == null) {
|
|
1862
1903
|
promises.push(this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} WHERE "guid"=decode(@guid, 'hex');`, {
|
|
1863
1904
|
etypes: [etype],
|
|
1864
1905
|
params: {
|
|
@@ -1878,13 +1919,15 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1878
1919
|
},
|
|
1879
1920
|
}));
|
|
1880
1921
|
}
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1922
|
+
if (only == null || only === 'tokens') {
|
|
1923
|
+
promises.push(this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}tokens_${etype}`)} WHERE "guid"=decode(@guid, 'hex');`, {
|
|
1924
|
+
etypes: [etype],
|
|
1925
|
+
params: {
|
|
1926
|
+
guid,
|
|
1927
|
+
},
|
|
1928
|
+
}));
|
|
1929
|
+
}
|
|
1930
|
+
if (only == null) {
|
|
1888
1931
|
promises.push(this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}uniques_${etype}`)} WHERE "guid"=decode(@guid, 'hex');`, {
|
|
1889
1932
|
etypes: [etype],
|
|
1890
1933
|
params: {
|
|
@@ -1894,14 +1937,23 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1894
1937
|
}
|
|
1895
1938
|
await Promise.all(promises);
|
|
1896
1939
|
promises = [];
|
|
1897
|
-
if (
|
|
1898
|
-
|
|
1940
|
+
if (only == null) {
|
|
1941
|
+
let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull } = this.removeAndReturnACValues(etype, {}, sdata);
|
|
1942
|
+
await this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate", "user", "group", "acUser", "acGroup", "acOther", "acRead", "acWrite", "acFull") VALUES (decode(@guid, 'hex'), @tags, @cdate, @mdate, ${user == null ? '@user' : "decode(@user, 'hex')"}, ${group == null ? '@group' : "decode(@group, 'hex')"}, @acUser, @acGroup, @acOther, ${!acRead?.length ? '@acRead' : "array(SELECT decode(n, 'hex') FROM unnest(@acRead::text[]) AS n)"}, ${!acWrite?.length ? '@acWrite' : "array(SELECT decode(n, 'hex') FROM unnest(@acWrite::text[]) AS n)"}, ${!acFull?.length ? '@acFull' : "array(SELECT decode(n, 'hex') FROM unnest(@acFull::text[]) AS n)"});`, {
|
|
1899
1943
|
etypes: [etype],
|
|
1900
1944
|
params: {
|
|
1901
1945
|
guid,
|
|
1902
1946
|
tags,
|
|
1903
1947
|
cdate: isNaN(cdate) ? null : cdate,
|
|
1904
1948
|
mdate: isNaN(mdate) ? null : mdate,
|
|
1949
|
+
user,
|
|
1950
|
+
group,
|
|
1951
|
+
acUser,
|
|
1952
|
+
acGroup,
|
|
1953
|
+
acOther,
|
|
1954
|
+
acRead,
|
|
1955
|
+
acWrite,
|
|
1956
|
+
acFull,
|
|
1905
1957
|
},
|
|
1906
1958
|
});
|
|
1907
1959
|
for (const name in sdata) {
|
|
@@ -1945,45 +1997,64 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
1945
1997
|
}
|
|
1946
1998
|
}
|
|
1947
1999
|
}
|
|
2000
|
+
if (only === 'tilmeldAC') {
|
|
2001
|
+
let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull } = this.removeAndReturnACValues(etype, {}, sdata);
|
|
2002
|
+
promises.push(this.queryRun(`UPDATE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} SET "user"=${user == null ? '@user' : "decode(@user, 'hex')"}, "group"=${group == null ? '@group' : "decode(@group, 'hex')"}, "acUser"=@acUser, "acGroup"=@acGroup, "acOther"=@acOther, "acRead"=${!acRead?.length ? '@acRead' : "array(SELECT decode(n, 'hex') FROM unnest(@acRead::text[]) AS n)"}, "acWrite"=${!acWrite?.length ? '@acWrite' : "array(SELECT decode(n, 'hex') FROM unnest(@acWrite::text[]) AS n)"}, "acFull"=${!acFull?.length ? '@acFull' : "array(SELECT decode(n, 'hex') FROM unnest(@acFull::text[]) AS n)"} WHERE "guid"=decode(@guid, 'hex');`, {
|
|
2003
|
+
etypes: [etype],
|
|
2004
|
+
params: {
|
|
2005
|
+
user,
|
|
2006
|
+
group,
|
|
2007
|
+
acUser,
|
|
2008
|
+
acGroup,
|
|
2009
|
+
acOther,
|
|
2010
|
+
acRead,
|
|
2011
|
+
acWrite,
|
|
2012
|
+
acFull,
|
|
2013
|
+
guid,
|
|
2014
|
+
},
|
|
2015
|
+
}));
|
|
2016
|
+
}
|
|
1948
2017
|
const EntityClass = this.nymph.getEntityClassByEtype(etype);
|
|
1949
|
-
|
|
1950
|
-
let
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
2018
|
+
if (only == null || only === 'tokens') {
|
|
2019
|
+
for (let name in sdata) {
|
|
2020
|
+
let tokenString = null;
|
|
2021
|
+
try {
|
|
2022
|
+
tokenString = EntityClass.getFTSText(name, JSON.parse(sdata[name]));
|
|
2023
|
+
}
|
|
2024
|
+
catch (e) {
|
|
2025
|
+
// Ignore error.
|
|
2026
|
+
}
|
|
2027
|
+
if (tokenString != null) {
|
|
2028
|
+
const tokens = this.tokenizer.tokenize(tokenString);
|
|
2029
|
+
while (tokens.length) {
|
|
2030
|
+
const currentTokens = tokens.splice(0, 100);
|
|
2031
|
+
const params = {
|
|
2032
|
+
guid,
|
|
2033
|
+
name,
|
|
2034
|
+
};
|
|
2035
|
+
const values = [];
|
|
2036
|
+
for (let i = 0; i < currentTokens.length; i++) {
|
|
2037
|
+
const token = currentTokens[i];
|
|
2038
|
+
params['token' + i] = token.token;
|
|
2039
|
+
params['position' + i] = token.position;
|
|
2040
|
+
params['stem' + i] = token.stem;
|
|
2041
|
+
values.push("(decode(@guid, 'hex'), @name, @token" +
|
|
2042
|
+
i +
|
|
2043
|
+
', @position' +
|
|
2044
|
+
i +
|
|
2045
|
+
', @stem' +
|
|
2046
|
+
i +
|
|
2047
|
+
')');
|
|
2048
|
+
}
|
|
2049
|
+
promises.push(this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}tokens_${etype}`)} ("guid", "name", "token", "position", "stem") VALUES ${values.join(', ')};`, {
|
|
2050
|
+
etypes: [etype],
|
|
2051
|
+
params,
|
|
2052
|
+
}));
|
|
1978
2053
|
}
|
|
1979
|
-
promises.push(this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}tokens_${etype}`)} ("guid", "name", "token", "position", "stem") VALUES ${values.join(', ')};`, {
|
|
1980
|
-
etypes: [etype],
|
|
1981
|
-
params,
|
|
1982
|
-
}));
|
|
1983
2054
|
}
|
|
1984
2055
|
}
|
|
1985
2056
|
}
|
|
1986
|
-
if (
|
|
2057
|
+
if (only == null) {
|
|
1987
2058
|
const uniques = await EntityClass.getUniques({
|
|
1988
2059
|
guid,
|
|
1989
2060
|
cdate,
|
|
@@ -2215,12 +2286,21 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
2215
2286
|
Object.keys(sdata).length === 0) {
|
|
2216
2287
|
return false;
|
|
2217
2288
|
}
|
|
2218
|
-
|
|
2289
|
+
let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull, } = this.removeAndReturnACValues(etype, data, sdata);
|
|
2290
|
+
await this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate", "user", "group", "acUser", "acGroup", "acOther", "acRead", "acWrite", "acFull") VALUES (decode(@guid, 'hex'), @tags, @cdate, @cdate, ${user == null ? '@user' : "decode(@user, 'hex')"}, ${group == null ? '@group' : "decode(@group, 'hex')"}, @acUser, @acGroup, @acOther, ${!acRead?.length ? '@acRead' : "array(SELECT decode(n, 'hex') FROM unnest(@acRead::text[]) AS n)"}, ${!acWrite?.length ? '@acWrite' : "array(SELECT decode(n, 'hex') FROM unnest(@acWrite::text[]) AS n)"}, ${!acFull?.length ? '@acFull' : "array(SELECT decode(n, 'hex') FROM unnest(@acFull::text[]) AS n)"});`, {
|
|
2219
2291
|
etypes: [etype],
|
|
2220
2292
|
params: {
|
|
2221
2293
|
guid,
|
|
2222
2294
|
tags,
|
|
2223
2295
|
cdate,
|
|
2296
|
+
user,
|
|
2297
|
+
group,
|
|
2298
|
+
acUser,
|
|
2299
|
+
acGroup,
|
|
2300
|
+
acOther,
|
|
2301
|
+
acRead,
|
|
2302
|
+
acWrite,
|
|
2303
|
+
acFull,
|
|
2224
2304
|
},
|
|
2225
2305
|
});
|
|
2226
2306
|
await insertData(guid, data, sdata, uniques, etype);
|
|
@@ -2230,6 +2310,7 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
2230
2310
|
Object.keys(sdata).length === 0) {
|
|
2231
2311
|
return false;
|
|
2232
2312
|
}
|
|
2313
|
+
let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull, } = this.removeAndReturnACValues(etype, data, sdata);
|
|
2233
2314
|
const promises = [];
|
|
2234
2315
|
promises.push(this.queryRun(`SELECT 1 FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`, {
|
|
2235
2316
|
etypes: [etype],
|
|
@@ -2262,11 +2343,19 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
2262
2343
|
},
|
|
2263
2344
|
}));
|
|
2264
2345
|
await Promise.all(promises);
|
|
2265
|
-
const info = await this.queryRun(`UPDATE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} SET "tags"=@tags, "mdate"=@mdate WHERE "guid"=decode(@guid, 'hex') AND "mdate" <= @emdate;`, {
|
|
2346
|
+
const info = await this.queryRun(`UPDATE ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} SET "tags"=@tags, "mdate"=@mdate, "user"=${user == null ? '@user' : "decode(@user, 'hex')"}, "group"=${group == null ? '@group' : "decode(@group, 'hex')"}, "acUser"=@acUser, "acGroup"=@acGroup, "acOther"=@acOther, "acRead"=${!acRead?.length ? '@acRead' : "array(SELECT decode(n, 'hex') FROM unnest(@acRead::text[]) AS n)"}, "acWrite"=${!acWrite?.length ? '@acWrite' : "array(SELECT decode(n, 'hex') FROM unnest(@acWrite::text[]) AS n)"}, "acFull"=${!acFull?.length ? '@acFull' : "array(SELECT decode(n, 'hex') FROM unnest(@acFull::text[]) AS n)"} WHERE "guid"=decode(@guid, 'hex') AND "mdate" <= @emdate;`, {
|
|
2266
2347
|
etypes: [etype],
|
|
2267
2348
|
params: {
|
|
2268
2349
|
tags,
|
|
2269
2350
|
mdate,
|
|
2351
|
+
user,
|
|
2352
|
+
group,
|
|
2353
|
+
acUser,
|
|
2354
|
+
acGroup,
|
|
2355
|
+
acOther,
|
|
2356
|
+
acRead,
|
|
2357
|
+
acWrite,
|
|
2358
|
+
acFull,
|
|
2270
2359
|
guid,
|
|
2271
2360
|
emdate: isNaN(Number(entity.mdate)) ? 0 : Number(entity.mdate),
|
|
2272
2361
|
},
|
|
@@ -2408,15 +2497,42 @@ export default class PostgreSQLDriver extends NymphDriver {
|
|
|
2408
2497
|
if (!table2 || !table2.table_name) {
|
|
2409
2498
|
return 'tokens';
|
|
2410
2499
|
}
|
|
2500
|
+
const table3 = await this.queryGet('SELECT "table_name" AS "table_name" FROM "information_schema"."tables" WHERE "table_catalog"=@db AND "table_schema"=\'public\' AND "table_name" LIKE @prefix LIMIT 1;', {
|
|
2501
|
+
params: {
|
|
2502
|
+
db: this.config.database,
|
|
2503
|
+
prefix: this.prefix + 'entities_' + '%',
|
|
2504
|
+
},
|
|
2505
|
+
});
|
|
2506
|
+
if (table3?.name) {
|
|
2507
|
+
const result = await this.queryGet('SELECT 1 AS "exists" FROM "information_schema"."columns" WHERE "table_catalog"=@db AND "table_schema"=\'public\' AND "table_name"=@table AND "column_name"=\'user\';', {
|
|
2508
|
+
params: {
|
|
2509
|
+
db: this.config.database,
|
|
2510
|
+
table: table3.table_name,
|
|
2511
|
+
},
|
|
2512
|
+
});
|
|
2513
|
+
if (!result?.exists) {
|
|
2514
|
+
return 'tilmeldColumns';
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2411
2517
|
return false;
|
|
2412
2518
|
}
|
|
2413
|
-
async liveMigration(
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2519
|
+
async liveMigration(migrationType) {
|
|
2520
|
+
if (migrationType === 'tokenTables') {
|
|
2521
|
+
const etypes = await this.getEtypes();
|
|
2522
|
+
const connection = await this.getConnection(true);
|
|
2523
|
+
for (let etype of etypes) {
|
|
2524
|
+
await this.createTokensTable(etype, connection);
|
|
2525
|
+
}
|
|
2526
|
+
connection.done();
|
|
2527
|
+
}
|
|
2528
|
+
else if (migrationType === 'tilmeldColumns') {
|
|
2529
|
+
const etypes = await this.getEtypes();
|
|
2530
|
+
const connection = await this.getConnection(true);
|
|
2531
|
+
for (let etype of etypes) {
|
|
2532
|
+
await this.addTilmeldColumnsAndIndexes(etype, connection);
|
|
2533
|
+
}
|
|
2534
|
+
connection.done();
|
|
2418
2535
|
}
|
|
2419
|
-
connection.done();
|
|
2420
2536
|
}
|
|
2421
2537
|
}
|
|
2422
2538
|
//# sourceMappingURL=PostgreSQLDriver.js.map
|