@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)) {
@@ -3993,5 +4010,5 @@ export {
3993
4010
  bumpReorgEpoch
3994
4011
  };
3995
4012
 
3996
- //# debugId=C09B9607BACD80D164756E2164756E21
4013
+ //# debugId=15E6E4E6D58CF62F64756E2164756E21
3997
4014
  //# sourceMappingURL=catchup.js.map