@openhi/constructs 0.0.110 → 0.0.111

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.
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  createRoleOperation
3
3
  } from "./chunk-AJ3G3THO.mjs";
4
+ import {
5
+ buildSchemaBootstrapStatements
6
+ } from "./chunk-2O3CXY2C.mjs";
4
7
  import {
5
8
  getRoleByIdOperation
6
9
  } from "./chunk-7FUAMZOF.mjs";
@@ -3727,6 +3730,7 @@ var DataApiPostgresQueryRunner = class {
3727
3730
  this.schema = options.schema;
3728
3731
  }
3729
3732
  async query(sql, params) {
3733
+ await this.ensureSchemaBootstrapped();
3730
3734
  const out = await this.client.send(
3731
3735
  new ExecuteStatementCommand({
3732
3736
  resourceArn: this.clusterArn,
@@ -3752,6 +3756,42 @@ var DataApiPostgresQueryRunner = class {
3752
3756
  }
3753
3757
  return JSON.parse(out.formattedRecords);
3754
3758
  }
3759
+ /**
3760
+ * Run `CREATE SCHEMA / CREATE TABLE / CREATE INDEX` idempotent DDL once per
3761
+ * runner instance. The replication Lambda's cold start does the same thing
3762
+ * (data-store-postgres-replication.handler) but in a fresh environment with
3763
+ * no DynamoDB writes yet the read path can be the first thing that touches
3764
+ * the cluster — without this, every search returns
3765
+ * `relation "<schema>.resources" does not exist` until something has been
3766
+ * written. Memoized so subsequent queries on a warm container don't pay the
3767
+ * DDL cost; resets the promise on failure so the next call retries.
3768
+ *
3769
+ * Data API's `ExecuteStatement` accepts only a single SQL statement per
3770
+ * call, so each DDL statement from `buildSchemaBootstrapStatements` is
3771
+ * issued individually. `IF NOT EXISTS` on every statement makes this safe
3772
+ * to race across concurrent containers.
3773
+ */
3774
+ async ensureSchemaBootstrapped() {
3775
+ if (!this.bootstrapPromise) {
3776
+ this.bootstrapPromise = this.runBootstrap().catch((err) => {
3777
+ this.bootstrapPromise = void 0;
3778
+ throw err;
3779
+ });
3780
+ }
3781
+ return this.bootstrapPromise;
3782
+ }
3783
+ async runBootstrap() {
3784
+ for (const statement of buildSchemaBootstrapStatements(this.schema)) {
3785
+ await this.client.send(
3786
+ new ExecuteStatementCommand({
3787
+ resourceArn: this.clusterArn,
3788
+ secretArn: this.secretArn,
3789
+ database: this.database,
3790
+ sql: statement
3791
+ })
3792
+ );
3793
+ }
3794
+ }
3755
3795
  };
3756
3796
  function qualifyResourcesTable(sql, schema) {
3757
3797
  return sql.replace(