@nymphjs/driver-postgresql 1.0.0-beta.105 → 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 CHANGED
@@ -3,6 +3,19 @@
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
+
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)
14
+
15
+ ### Bug Fixes
16
+
17
+ - don't sort qref queries unless explicitly told to ([e92c413](https://github.com/sciactive/nymphjs/commit/e92c413800032a9347a06f965281263a55c9547b))
18
+
6
19
  # [1.0.0-beta.105](https://github.com/sciactive/nymphjs/compare/v1.0.0-beta.104...v1.0.0-beta.105) (2025-12-04)
7
20
 
8
21
  ### Features
@@ -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(_migrationType: 'tokenTables'): Promise<void>;
155
+ needsMigration(): Promise<'json' | 'tokens' | 'tilmeldColumns' | false>;
156
+ liveMigration(migrationType: 'tokenTables' | 'tilmeldColumns'): Promise<void>;
147
157
  }
148
158
  export {};
@@ -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}`)} (
@@ -1558,14 +1596,14 @@ export default class PostgreSQLDriver extends NymphDriver {
1558
1596
  break;
1559
1597
  case 'selector':
1560
1598
  case '!selector':
1561
- const subquery = this.makeEntityQuery(options, [curValue], etype, count, params, true, tableSuffix, etypes);
1599
+ const innerquery = this.makeEntityQuery({ ...options, sort: null, limit: undefined }, [curValue], etype, count, params, true, tableSuffix, etypes);
1562
1600
  if (curQuery) {
1563
1601
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1564
1602
  }
1565
1603
  curQuery +=
1566
1604
  (xor(typeIsNot, clauseNot) ? 'NOT ' : '') +
1567
1605
  '(' +
1568
- subquery.query +
1606
+ innerquery.query +
1569
1607
  ')';
1570
1608
  break;
1571
1609
  case 'qref':
@@ -1574,7 +1612,12 @@ export default class PostgreSQLDriver extends NymphDriver {
1574
1612
  const [qrefOptions, ...qrefSelectors] = curValue[1];
1575
1613
  const QrefEntityClass = qrefOptions.class;
1576
1614
  etypes.push(QrefEntityClass.ETYPE);
1577
- const qrefQuery = this.makeEntityQuery({ ...qrefOptions, return: 'guid', class: QrefEntityClass }, qrefSelectors, QrefEntityClass.ETYPE, count, params, false, makeTableSuffix(), etypes, 'r' + referenceTableSuffix + '."reference"');
1615
+ const qrefQuery = this.makeEntityQuery({
1616
+ ...qrefOptions,
1617
+ sort: qrefOptions.sort ?? null,
1618
+ return: 'guid',
1619
+ class: QrefEntityClass,
1620
+ }, qrefSelectors, QrefEntityClass.ETYPE, count, params, false, makeTableSuffix(), etypes, 'r' + referenceTableSuffix + '."reference"');
1578
1621
  if (curQuery) {
1579
1622
  curQuery += typeIsOr ? ' OR ' : ' AND ';
1580
1623
  }
@@ -1845,15 +1888,18 @@ export default class PostgreSQLDriver extends NymphDriver {
1845
1888
  return result?.cur_uid == null ? null : Number(result.cur_uid);
1846
1889
  }
1847
1890
  async importEntity(entity) {
1848
- return await this.importEntityInternal(entity, false);
1891
+ return await this.importEntityInternal(entity);
1849
1892
  }
1850
1893
  async importEntityTokens(entity) {
1851
- return await this.importEntityInternal(entity, true);
1894
+ return await this.importEntityInternal(entity, { only: 'tokens' });
1895
+ }
1896
+ async importEntityTilmeldAC(entity) {
1897
+ return await this.importEntityInternal(entity, { only: 'tilmeldAC' });
1852
1898
  }
1853
- async importEntityInternal({ guid, cdate, mdate, tags, sdata, etype, }, onlyTokens) {
1899
+ async importEntityInternal({ guid, cdate, mdate, tags, sdata, etype, }, { only = undefined } = {}) {
1854
1900
  try {
1855
1901
  let promises = [];
1856
- if (!onlyTokens) {
1902
+ if (only == null) {
1857
1903
  promises.push(this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} WHERE "guid"=decode(@guid, 'hex');`, {
1858
1904
  etypes: [etype],
1859
1905
  params: {
@@ -1873,13 +1919,15 @@ export default class PostgreSQLDriver extends NymphDriver {
1873
1919
  },
1874
1920
  }));
1875
1921
  }
1876
- promises.push(this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}tokens_${etype}`)} WHERE "guid"=decode(@guid, 'hex');`, {
1877
- etypes: [etype],
1878
- params: {
1879
- guid,
1880
- },
1881
- }));
1882
- if (!onlyTokens) {
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) {
1883
1931
  promises.push(this.queryRun(`DELETE FROM ${PostgreSQLDriver.escape(`${this.prefix}uniques_${etype}`)} WHERE "guid"=decode(@guid, 'hex');`, {
1884
1932
  etypes: [etype],
1885
1933
  params: {
@@ -1889,14 +1937,23 @@ export default class PostgreSQLDriver extends NymphDriver {
1889
1937
  }
1890
1938
  await Promise.all(promises);
1891
1939
  promises = [];
1892
- if (!onlyTokens) {
1893
- await this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate") VALUES (decode(@guid, 'hex'), @tags, @cdate, @mdate);`, {
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)"});`, {
1894
1943
  etypes: [etype],
1895
1944
  params: {
1896
1945
  guid,
1897
1946
  tags,
1898
1947
  cdate: isNaN(cdate) ? null : cdate,
1899
1948
  mdate: isNaN(mdate) ? null : mdate,
1949
+ user,
1950
+ group,
1951
+ acUser,
1952
+ acGroup,
1953
+ acOther,
1954
+ acRead,
1955
+ acWrite,
1956
+ acFull,
1900
1957
  },
1901
1958
  });
1902
1959
  for (const name in sdata) {
@@ -1940,45 +1997,64 @@ export default class PostgreSQLDriver extends NymphDriver {
1940
1997
  }
1941
1998
  }
1942
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
+ }
1943
2017
  const EntityClass = this.nymph.getEntityClassByEtype(etype);
1944
- for (let name in sdata) {
1945
- let tokenString = null;
1946
- try {
1947
- tokenString = EntityClass.getFTSText(name, JSON.parse(sdata[name]));
1948
- }
1949
- catch (e) {
1950
- // Ignore error.
1951
- }
1952
- if (tokenString != null) {
1953
- const tokens = this.tokenizer.tokenize(tokenString);
1954
- while (tokens.length) {
1955
- const currentTokens = tokens.splice(0, 100);
1956
- const params = {
1957
- guid,
1958
- name,
1959
- };
1960
- const values = [];
1961
- for (let i = 0; i < currentTokens.length; i++) {
1962
- const token = currentTokens[i];
1963
- params['token' + i] = token.token;
1964
- params['position' + i] = token.position;
1965
- params['stem' + i] = token.stem;
1966
- values.push("(decode(@guid, 'hex'), @name, @token" +
1967
- i +
1968
- ', @position' +
1969
- i +
1970
- ', @stem' +
1971
- i +
1972
- ')');
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
+ }));
1973
2053
  }
1974
- promises.push(this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}tokens_${etype}`)} ("guid", "name", "token", "position", "stem") VALUES ${values.join(', ')};`, {
1975
- etypes: [etype],
1976
- params,
1977
- }));
1978
2054
  }
1979
2055
  }
1980
2056
  }
1981
- if (!onlyTokens) {
2057
+ if (only == null) {
1982
2058
  const uniques = await EntityClass.getUniques({
1983
2059
  guid,
1984
2060
  cdate,
@@ -2210,12 +2286,21 @@ export default class PostgreSQLDriver extends NymphDriver {
2210
2286
  Object.keys(sdata).length === 0) {
2211
2287
  return false;
2212
2288
  }
2213
- await this.queryRun(`INSERT INTO ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} ("guid", "tags", "cdate", "mdate") VALUES (decode(@guid, 'hex'), @tags, @cdate, @cdate);`, {
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)"});`, {
2214
2291
  etypes: [etype],
2215
2292
  params: {
2216
2293
  guid,
2217
2294
  tags,
2218
2295
  cdate,
2296
+ user,
2297
+ group,
2298
+ acUser,
2299
+ acGroup,
2300
+ acOther,
2301
+ acRead,
2302
+ acWrite,
2303
+ acFull,
2219
2304
  },
2220
2305
  });
2221
2306
  await insertData(guid, data, sdata, uniques, etype);
@@ -2225,6 +2310,7 @@ export default class PostgreSQLDriver extends NymphDriver {
2225
2310
  Object.keys(sdata).length === 0) {
2226
2311
  return false;
2227
2312
  }
2313
+ let { user, group, acUser, acGroup, acOther, acRead, acWrite, acFull, } = this.removeAndReturnACValues(etype, data, sdata);
2228
2314
  const promises = [];
2229
2315
  promises.push(this.queryRun(`SELECT 1 FROM ${PostgreSQLDriver.escape(`${this.prefix}entities_${etype}`)} WHERE "guid"=decode(@guid, 'hex') FOR UPDATE;`, {
2230
2316
  etypes: [etype],
@@ -2257,11 +2343,19 @@ export default class PostgreSQLDriver extends NymphDriver {
2257
2343
  },
2258
2344
  }));
2259
2345
  await Promise.all(promises);
2260
- 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;`, {
2261
2347
  etypes: [etype],
2262
2348
  params: {
2263
2349
  tags,
2264
2350
  mdate,
2351
+ user,
2352
+ group,
2353
+ acUser,
2354
+ acGroup,
2355
+ acOther,
2356
+ acRead,
2357
+ acWrite,
2358
+ acFull,
2265
2359
  guid,
2266
2360
  emdate: isNaN(Number(entity.mdate)) ? 0 : Number(entity.mdate),
2267
2361
  },
@@ -2403,15 +2497,42 @@ export default class PostgreSQLDriver extends NymphDriver {
2403
2497
  if (!table2 || !table2.table_name) {
2404
2498
  return 'tokens';
2405
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
+ }
2406
2517
  return false;
2407
2518
  }
2408
- async liveMigration(_migrationType) {
2409
- const etypes = await this.getEtypes();
2410
- const connection = await this.getConnection(true);
2411
- for (let etype of etypes) {
2412
- await this.createTokensTable(etype, connection);
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();
2413
2535
  }
2414
- connection.done();
2415
2536
  }
2416
2537
  }
2417
2538
  //# sourceMappingURL=PostgreSQLDriver.js.map