@coffre/db 0.1.11 → 0.1.12
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/connect.d.ts +1 -1
- package/dist/{database-BhLco7OA.d.ts → database-CNMfHZwF.d.ts} +1 -1
- package/dist/dialect.d.ts +1 -1
- package/dist/hyperdrive.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/log.d.ts +1 -1
- package/dist/migrations/postgres/0001_remove_syncs.sql +13 -0
- package/dist/migrations/postgres/meta/0001_snapshot.json +1707 -0
- package/dist/migrations/postgres/meta/_journal.json +7 -0
- package/dist/migrations/sqlite/0001_remove_syncs.sql +13 -0
- package/dist/migrations/sqlite/meta/0001_snapshot.json +1575 -0
- package/dist/migrations/sqlite/meta/_journal.json +7 -0
- package/dist/portable.d.ts +2 -2
- package/dist/{relations-DqgxtlKu.js → relations-BfR3JjT1.js} +2 -22
- package/dist/{schema-Cd4WOnB5.d.ts → schema-AmvM6w0D.d.ts} +2 -362
- package/dist/schema-sqlite.d.ts +1 -369
- package/dist/schema-sqlite.js +5 -59
- package/dist/schema-version.d.ts +5 -3
- package/dist/schema-version.js +4 -2
- package/dist/schema.d.ts +2 -2
- package/dist/schema.js +5 -79
- package/package.json +2 -2
- package/src/baseline.ts +11 -19
- package/src/migrations/postgres/0001_remove_syncs.sql +13 -0
- package/src/migrations/postgres/meta/0001_snapshot.json +1707 -0
- package/src/migrations/postgres/meta/_journal.json +7 -0
- package/src/migrations/sqlite/0001_remove_syncs.sql +13 -0
- package/src/migrations/sqlite/meta/0001_snapshot.json +1575 -0
- package/src/migrations/sqlite/meta/_journal.json +7 -0
- package/src/relations.ts +1 -14
- package/src/schema-version.ts +4 -2
- package/src/schema.sqlite.ts +1 -65
- package/src/schema.ts +1 -81
package/src/relations.ts
CHANGED
|
@@ -6,8 +6,7 @@ import type * as schema from './schema.ts';
|
|
|
6
6
|
* What both schemas share beyond their columns: the relations and the
|
|
7
7
|
* one generated column.
|
|
8
8
|
*
|
|
9
|
-
* Relations are for Drizzle's relational queries (`db.query.
|
|
10
|
-
* .findMany({ with })`), which read a row and what hangs off it in one
|
|
9
|
+
* Relations are for Drizzle's relational queries (`db.query.secrets.findMany({ with })`), which read a row and what hangs off it in one
|
|
11
10
|
* statement on every dialect. They add no constraints; the foreign keys in
|
|
12
11
|
* each schema do that. Each schema calls this with its own tables, so a
|
|
13
12
|
* relational query on SQLite joins SQLite tables.
|
|
@@ -18,8 +17,6 @@ export function relationsOf(t: Pick<
|
|
|
18
17
|
| 'environments'
|
|
19
18
|
| 'secrets'
|
|
20
19
|
| 'secretVersions'
|
|
21
|
-
| 'syncs'
|
|
22
|
-
| 'syncKeys'
|
|
23
20
|
>) {
|
|
24
21
|
return {
|
|
25
22
|
environmentsRelations: relations(t.environments, ({ one }) => ({
|
|
@@ -31,16 +28,6 @@ export function relationsOf(t: Pick<
|
|
|
31
28
|
environment: one(t.environments, { fields: [t.secrets.environmentId], references: [t.environments.id] }),
|
|
32
29
|
})),
|
|
33
30
|
|
|
34
|
-
syncsRelations: relations(t.syncs, ({ one, many }) => ({
|
|
35
|
-
project: one(t.projects, { fields: [t.syncs.projectId], references: [t.projects.id] }),
|
|
36
|
-
environment: one(t.environments, { fields: [t.syncs.environmentId], references: [t.environments.id] }),
|
|
37
|
-
credential: one(t.secrets, { fields: [t.syncs.credentialSecretId], references: [t.secrets.id] }),
|
|
38
|
-
keys: many(t.syncKeys),
|
|
39
|
-
})),
|
|
40
|
-
|
|
41
|
-
syncKeysRelations: relations(t.syncKeys, ({ one }) => ({
|
|
42
|
-
sync: one(t.syncs, { fields: [t.syncKeys.syncId], references: [t.syncs.id] }),
|
|
43
|
-
})),
|
|
44
31
|
};
|
|
45
32
|
}
|
|
46
33
|
|
package/src/schema-version.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { engineOf, type Engine } from './dialect.ts';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Minimum migration prefix required by this application image, per engine:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Advance this only when the runtime needs the new schema. The sync-removal
|
|
7
|
+
* migration only drops unused tables: new code works with either prefix,
|
|
8
|
+
* so Workers Builds can deploy before an owner runs the migration.
|
|
9
|
+
* Applied migrations remain immutable (see baseline.ts).
|
|
8
10
|
*/
|
|
9
11
|
export const REQUIRED_MIGRATIONS: Record<Engine, number> = { postgres: 1, sqlite: 1 };
|
|
10
12
|
|
package/src/schema.sqlite.ts
CHANGED
|
@@ -439,73 +439,9 @@ export const deviceAuthorizations = sqliteTable(
|
|
|
439
439
|
],
|
|
440
440
|
);
|
|
441
441
|
|
|
442
|
-
export const syncs = sqliteTable(
|
|
443
|
-
'syncs',
|
|
444
|
-
{
|
|
445
|
-
id: text().primaryKey(),
|
|
446
|
-
projectId: text('project_id').notNull(),
|
|
447
|
-
environmentId: text('environment_id').notNull(),
|
|
448
|
-
provider: text().notNull(),
|
|
449
|
-
config: text().notNull(),
|
|
450
|
-
credentialSecretId: text('credential_secret_id').notNull(),
|
|
451
|
-
createdAt: createdAt(),
|
|
452
|
-
createdBy: text('created_by').notNull(),
|
|
453
|
-
pausedAt: time('paused_at'),
|
|
454
|
-
archivedAt: time('archived_at'),
|
|
455
|
-
leaseUntil: time('lease_until'),
|
|
456
|
-
lastRunAt: time('last_run_at'),
|
|
457
|
-
lastStatus: text('last_status'),
|
|
458
|
-
lastError: text('last_error'),
|
|
459
|
-
},
|
|
460
|
-
(table) => [
|
|
461
|
-
check('syncs_config_check', sql`json_valid(${table.config})`),
|
|
462
|
-
check(
|
|
463
|
-
'syncs_last_status_check',
|
|
464
|
-
sql`${table.lastStatus} IS NULL OR ${table.lastStatus} IN ('ok', 'partial', 'failed')`,
|
|
465
|
-
),
|
|
466
|
-
foreignKey({
|
|
467
|
-
name: 'syncs_environment_in_project',
|
|
468
|
-
columns: [table.environmentId, table.projectId],
|
|
469
|
-
foreignColumns: [environments.id, environments.projectId],
|
|
470
|
-
}).onDelete('restrict'),
|
|
471
|
-
foreignKey({
|
|
472
|
-
name: 'syncs_credential_secret_id_fkey',
|
|
473
|
-
columns: [table.credentialSecretId],
|
|
474
|
-
foreignColumns: [secrets.id],
|
|
475
|
-
}).onDelete('restrict'),
|
|
476
|
-
index('syncs_environment_idx').on(table.environmentId),
|
|
477
|
-
],
|
|
478
|
-
);
|
|
479
|
-
|
|
480
|
-
export const syncKeys = sqliteTable(
|
|
481
|
-
'sync_keys',
|
|
482
|
-
{
|
|
483
|
-
syncId: text('sync_id').notNull(),
|
|
484
|
-
key: text().notNull(),
|
|
485
|
-
secretVersionId: text('secret_version_id'),
|
|
486
|
-
pushedAt: time('pushed_at').notNull().default(now),
|
|
487
|
-
removedAt: time('removed_at'),
|
|
488
|
-
},
|
|
489
|
-
(table) => [
|
|
490
|
-
primaryKey({ name: 'sync_keys_pkey', columns: [table.syncId, table.key] }),
|
|
491
|
-
foreignKey({
|
|
492
|
-
name: 'sync_keys_sync_id_fkey',
|
|
493
|
-
columns: [table.syncId],
|
|
494
|
-
foreignColumns: [syncs.id],
|
|
495
|
-
}).onDelete('restrict'),
|
|
496
|
-
foreignKey({
|
|
497
|
-
name: 'sync_keys_secret_version_id_fkey',
|
|
498
|
-
columns: [table.secretVersionId],
|
|
499
|
-
foreignColumns: [secretVersions.id],
|
|
500
|
-
}).onDelete('restrict'),
|
|
501
|
-
],
|
|
502
|
-
);
|
|
503
|
-
|
|
504
442
|
export const {
|
|
505
443
|
environmentsRelations,
|
|
506
444
|
secretsRelations,
|
|
507
|
-
syncsRelations,
|
|
508
|
-
syncKeysRelations,
|
|
509
445
|
} = relationsOf(
|
|
510
|
-
asPostgres({ projects, environments, secrets, secretVersions
|
|
446
|
+
asPostgres({ projects, environments, secrets, secretVersions }),
|
|
511
447
|
);
|
package/src/schema.ts
CHANGED
|
@@ -461,88 +461,8 @@ export const deviceAuthorizations = pgTable(
|
|
|
461
461
|
],
|
|
462
462
|
);
|
|
463
463
|
|
|
464
|
-
/**
|
|
465
|
-
* An environment kept in step with a third-party service: GitHub Actions
|
|
466
|
-
* secrets, Vercel or Railway variables, Worker secrets.
|
|
467
|
-
*
|
|
468
|
-
* The destination's API token is itself a coffre secret, referenced by id, so
|
|
469
|
-
* it is encrypted, versioned and audited like everything else and never sits
|
|
470
|
-
* in this table.
|
|
471
|
-
*/
|
|
472
|
-
export const syncs = pgTable(
|
|
473
|
-
'syncs',
|
|
474
|
-
{
|
|
475
|
-
id: uuid().primaryKey().defaultRandom(),
|
|
476
|
-
projectId: uuid('project_id').notNull(),
|
|
477
|
-
environmentId: uuid('environment_id').notNull(),
|
|
478
|
-
provider: text().notNull(),
|
|
479
|
-
config: text().notNull(),
|
|
480
|
-
credentialSecretId: uuid('credential_secret_id').notNull(),
|
|
481
|
-
createdAt: createdAt(),
|
|
482
|
-
createdBy: text('created_by').notNull(),
|
|
483
|
-
pausedAt: timestamp('paused_at', { withTimezone: true }),
|
|
484
|
-
archivedAt: timestamp('archived_at', { withTimezone: true }),
|
|
485
|
-
leaseUntil: timestamp('lease_until', { withTimezone: true }),
|
|
486
|
-
lastRunAt: timestamp('last_run_at', { withTimezone: true }),
|
|
487
|
-
lastStatus: text('last_status'),
|
|
488
|
-
lastError: text('last_error'),
|
|
489
|
-
},
|
|
490
|
-
(table) => [
|
|
491
|
-
check('syncs_config_check', sql`${table.config}::jsonb IS NOT NULL`),
|
|
492
|
-
check(
|
|
493
|
-
'syncs_last_status_check',
|
|
494
|
-
sql`${table.lastStatus} IS NULL OR ${table.lastStatus} IN ('ok', 'partial', 'failed')`,
|
|
495
|
-
),
|
|
496
|
-
foreignKey({
|
|
497
|
-
name: 'syncs_environment_in_project',
|
|
498
|
-
columns: [table.environmentId, table.projectId],
|
|
499
|
-
foreignColumns: [environments.id, environments.projectId],
|
|
500
|
-
}).onDelete('restrict'),
|
|
501
|
-
foreignKey({
|
|
502
|
-
name: 'syncs_credential_secret_id_fkey',
|
|
503
|
-
columns: [table.credentialSecretId],
|
|
504
|
-
foreignColumns: [secrets.id],
|
|
505
|
-
}).onDelete('restrict'),
|
|
506
|
-
index('syncs_environment_idx').on(table.environmentId),
|
|
507
|
-
],
|
|
508
|
-
);
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* What a sync last pushed, one row per key.
|
|
512
|
-
*
|
|
513
|
-
* Most destinations are write-only, so coffre cannot diff against them. It
|
|
514
|
-
* diffs against this instead: a key is stale when its secret has moved past
|
|
515
|
-
* the version recorded here. It is also the list of keys coffre may delete at
|
|
516
|
-
* the destination; a key it never pushed is never removed.
|
|
517
|
-
*/
|
|
518
|
-
export const syncKeys = pgTable(
|
|
519
|
-
'sync_keys',
|
|
520
|
-
{
|
|
521
|
-
syncId: uuid('sync_id').notNull(),
|
|
522
|
-
key: text().notNull(),
|
|
523
|
-
secretVersionId: uuid('secret_version_id'),
|
|
524
|
-
pushedAt: timestamp('pushed_at', { withTimezone: true }).notNull().defaultNow(),
|
|
525
|
-
removedAt: timestamp('removed_at', { withTimezone: true }),
|
|
526
|
-
},
|
|
527
|
-
(table) => [
|
|
528
|
-
primaryKey({ name: 'sync_keys_pkey', columns: [table.syncId, table.key] }),
|
|
529
|
-
foreignKey({
|
|
530
|
-
name: 'sync_keys_sync_id_fkey',
|
|
531
|
-
columns: [table.syncId],
|
|
532
|
-
foreignColumns: [syncs.id],
|
|
533
|
-
}).onDelete('restrict'),
|
|
534
|
-
foreignKey({
|
|
535
|
-
name: 'sync_keys_secret_version_id_fkey',
|
|
536
|
-
columns: [table.secretVersionId],
|
|
537
|
-
foreignColumns: [secretVersions.id],
|
|
538
|
-
}).onDelete('restrict'),
|
|
539
|
-
],
|
|
540
|
-
);
|
|
541
|
-
|
|
542
464
|
// For Drizzle's relational queries; see relations.ts.
|
|
543
465
|
export const {
|
|
544
466
|
environmentsRelations,
|
|
545
467
|
secretsRelations,
|
|
546
|
-
|
|
547
|
-
syncKeysRelations,
|
|
548
|
-
} = relationsOf({ projects, environments, secrets, secretVersions, syncs, syncKeys });
|
|
468
|
+
} = relationsOf({ projects, environments, secrets, secretVersions });
|