@systemfsoftware/timescale-drizzle 0.9.0 → 0.10.0

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/dist/cli.js CHANGED
@@ -94,7 +94,7 @@ const COMMENT = Symbol.for("timescale-drizzle.comment");
94
94
  function extrasKind(value) {
95
95
  if (typeof value !== "object" || value === null) return null;
96
96
  const kind = value[KIND];
97
- if (kind === "function" || kind === "trigger" || kind === "extension" || kind === "comment" || kind === "partitionedTable" || kind === "partition" || kind === "detach" || kind === "hypertable" || kind === "continuousAggregate" || kind === "viewDefinition" || kind === "grant") return kind;
97
+ if (kind === "function" || kind === "trigger" || kind === "extension" || kind === "comment" || kind === "partitionedTable" || kind === "partition" || kind === "detach" || kind === "hypertable" || kind === "continuousAggregate" || kind === "viewDefinition" || kind === "grant" || kind === "timescaleServer") return kind;
98
98
  return null;
99
99
  }
100
100
  function readComment(target) {
@@ -3177,8 +3177,34 @@ function bumpStamp(stamp) {
3177
3177
  const at = Date.UTC(Number(stamp.slice(0, 4)), Number(stamp.slice(4, 6)) - 1, Number(stamp.slice(6, 8)), Number(stamp.slice(8, 10)), Number(stamp.slice(10, 12)), Number(stamp.slice(12, 14)));
3178
3178
  return utcStamp(new Date(at + 1e3));
3179
3179
  }
3180
+ // src/server.ts
3181
+ function hypertableJobs(hypertable) {
3182
+ return [
3183
+ hypertable.columnstorePolicy,
3184
+ hypertable.retention,
3185
+ hypertable.reorder
3186
+ ].filter((job) => job !== null).length;
3187
+ }
3188
+ function aggregateJobs(aggregate) {
3189
+ return aggregate.refreshPolicies.length + [aggregate.columnstorePolicy, aggregate.retention].filter((job) => job !== null).length;
3190
+ }
3191
+ function declaredJobCount(extras) {
3192
+ return extras.hypertables.reduce((sum, hypertable) => sum + hypertableJobs(hypertable), 0) + extras.continuousAggregates.reduce((sum, aggregate) => sum + aggregateJobs(aggregate), 0);
3193
+ }
3194
+ function assertTimescaleServer(extras) {
3195
+ const problems = timescaleServerProblems(extras);
3196
+ if (problems.length > 0) throw new PgExtrasError(`timescaleServer: ${problems.join("; ")}`);
3197
+ }
3198
+ function timescaleServerProblems(extras) {
3199
+ if (extras.servers.length === 0) return [];
3200
+ if (extras.servers.length > 1) return [`the schema declares ${extras.servers.length} timescaleServer values; declare one`];
3201
+ const server = extras.servers[0];
3202
+ const jobs = declaredJobCount(extras);
3203
+ if (jobs > 0 && server.concurrentJobs === 0) return [`the schema declares ${jobs} TimescaleDB jobs and its timescaleServer allows 0 concurrent jobs`];
3204
+ return [];
3205
+ }
3180
3206
  // src/version.ts
3181
- const VERSION = "0.9.0";
3207
+ const VERSION = "0.10.0";
3182
3208
  // src/generate.ts
3183
3209
  const UP_HEADER = `-- Generated by timescale-drizzle ${VERSION}. Review before applying.`;
3184
3210
  const DOWN_HEADER = `-- Down SQL for timescale-drizzle ${VERSION}. drizzle-kit migrate does not run this file.`;
@@ -3192,6 +3218,7 @@ function loadStoredSnapshot(out) {
3192
3218
  }
3193
3219
  }
3194
3220
  function planExtras(extras, previous, casing) {
3221
+ assertTimescaleServer(extras);
3195
3222
  const next = snapshotExtras(extras, casing ? { casing } : void 0);
3196
3223
  return {
3197
3224
  next,
@@ -3241,7 +3268,8 @@ function collectExtras(modules) {
3241
3268
  hypertables: [],
3242
3269
  continuousAggregates: [],
3243
3270
  viewDefinitions: [],
3244
- grants: []
3271
+ grants: [],
3272
+ servers: []
3245
3273
  };
3246
3274
  const seen = /* @__PURE__ */ new Set();
3247
3275
  const list = Array.isArray(modules) ? modules : [modules];
@@ -3312,6 +3340,10 @@ function walk(value, extras, seen) {
3312
3340
  for (const dependency of definition.dependsOn) walk(dependency, extras, seen);
3313
3341
  return;
3314
3342
  }
3343
+ if (kind === "timescaleServer") {
3344
+ extras.servers.push(value);
3345
+ return;
3346
+ }
3315
3347
  if (kind === "grant") {
3316
3348
  const grant = value;
3317
3349
  extras.grants.push(grant);