@secondlayer/subgraphs 4.3.3 → 4.3.5

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.
@@ -41,6 +41,24 @@ function safeIndexName(name) {
41
41
  const hash = createHash("sha256").update(name).digest("hex").slice(0, 8);
42
42
  return `${name.slice(0, MAX_IDENT_BYTES - hash.length - 1)}_${hash}`;
43
43
  }
44
+ function emitIndexedColumnIndexDDL(schemaName, tableName, colName, opts) {
45
+ const concurrently = opts?.concurrently ? " CONCURRENTLY" : "";
46
+ const qualified = `${quotePgIdent(schemaName)}.${quotePgIdent(tableName)}`;
47
+ const plain = `idx_${schemaName}_${tableName}_${colName}`;
48
+ const composite = safeIndexName(`idx_${schemaName}_${tableName}_${colName}_id`);
49
+ const col = quotePgIdent(colName);
50
+ const id = quotePgIdent("_id");
51
+ return {
52
+ create: [
53
+ `CREATE INDEX${concurrently} IF NOT EXISTS ${quotePgIdent(plain)} ON ${qualified} (${col})`,
54
+ `CREATE INDEX${concurrently} IF NOT EXISTS ${quotePgIdent(composite)} ON ${qualified} (${col}, ${id})`
55
+ ],
56
+ drop: [
57
+ `DROP INDEX${concurrently} IF EXISTS ${quotePgIdent(schemaName)}.${quotePgIdent(plain)}`,
58
+ `DROP INDEX${concurrently} IF EXISTS ${quotePgIdent(schemaName)}.${quotePgIdent(composite)}`
59
+ ]
60
+ };
61
+ }
44
62
  function escapeLiteralDefault(value) {
45
63
  if (value === null || value === undefined)
46
64
  return "NULL";
@@ -82,8 +100,7 @@ function emitTableDDL(schemaName, tableName, tableDef) {
82
100
  statements.push(`CREATE INDEX IF NOT EXISTS ${quotePgIdent(`idx_${schemaName}_${tableName}_tx_id`)} ON ${qualifiedName} (_tx_id)`);
83
101
  for (const [colName, col] of Object.entries(tableDef.columns)) {
84
102
  if (col.indexed) {
85
- statements.push(`CREATE INDEX IF NOT EXISTS ${quotePgIdent(`idx_${schemaName}_${tableName}_${colName}`)} ON ${qualifiedName} (${quotePgIdent(colName)})`);
86
- statements.push(`CREATE INDEX IF NOT EXISTS ${quotePgIdent(safeIndexName(`idx_${schemaName}_${tableName}_${colName}_id`))} ON ${qualifiedName} (${quotePgIdent(colName)}, ${quotePgIdent("_id")})`);
103
+ statements.push(...emitIndexedColumnIndexDDL(schemaName, tableName, colName).create);
87
104
  }
88
105
  }
89
106
  for (const [colName, col] of Object.entries(tableDef.columns)) {
@@ -4567,5 +4584,5 @@ export {
4567
4584
  backfillSubgraph
4568
4585
  };
4569
4586
 
4570
- //# debugId=2F4BC80D6FDD19E164756E2164756E21
4587
+ //# debugId=1A3E7DE8C0B69A9C64756E2164756E21
4571
4588
  //# sourceMappingURL=reindex.js.map