@krantho/persistence-postgres 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/dist/auth-adapter.d.ts +23 -0
- package/dist/auth-adapter.d.ts.map +1 -0
- package/dist/auth-adapter.js +159 -0
- package/dist/auth-adapter.js.map +1 -0
- package/dist/content-migration.d.ts +14 -0
- package/dist/content-migration.d.ts.map +1 -0
- package/dist/content-migration.js +64 -0
- package/dist/content-migration.js.map +1 -0
- package/dist/content-query.d.ts +23 -0
- package/dist/content-query.d.ts.map +1 -0
- package/dist/content-query.js +170 -0
- package/dist/content-query.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/migration-runner.d.ts +29 -0
- package/dist/migration-runner.d.ts.map +1 -0
- package/dist/migration-runner.js +123 -0
- package/dist/migration-runner.js.map +1 -0
- package/dist/migrations/index.d.ts +4 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +32 -0
- package/dist/migrations/index.js.map +1 -0
- package/dist/migrations/v001-initial-schema.d.ts +10 -0
- package/dist/migrations/v001-initial-schema.d.ts.map +1 -0
- package/dist/migrations/v001-initial-schema.js +94 -0
- package/dist/migrations/v001-initial-schema.js.map +1 -0
- package/dist/migrations/v002-auth-tables.d.ts +8 -0
- package/dist/migrations/v002-auth-tables.d.ts.map +1 -0
- package/dist/migrations/v002-auth-tables.js +37 -0
- package/dist/migrations/v002-auth-tables.js.map +1 -0
- package/dist/migrations/v003-user-permissions.d.ts +6 -0
- package/dist/migrations/v003-user-permissions.d.ts.map +1 -0
- package/dist/migrations/v003-user-permissions.js +18 -0
- package/dist/migrations/v003-user-permissions.js.map +1 -0
- package/dist/migrations/v004-media-hotspot.d.ts +14 -0
- package/dist/migrations/v004-media-hotspot.d.ts.map +1 -0
- package/dist/migrations/v004-media-hotspot.js +25 -0
- package/dist/migrations/v004-media-hotspot.js.map +1 -0
- package/dist/migrations/v005-content-locks.d.ts +6 -0
- package/dist/migrations/v005-content-locks.d.ts.map +1 -0
- package/dist/migrations/v005-content-locks.js +21 -0
- package/dist/migrations/v005-content-locks.js.map +1 -0
- package/dist/migrations/v006-webhook-deliveries.d.ts +6 -0
- package/dist/migrations/v006-webhook-deliveries.d.ts.map +1 -0
- package/dist/migrations/v006-webhook-deliveries.js +24 -0
- package/dist/migrations/v006-webhook-deliveries.js.map +1 -0
- package/dist/migrations/v007-media-folders.d.ts +6 -0
- package/dist/migrations/v007-media-folders.d.ts.map +1 -0
- package/dist/migrations/v007-media-folders.js +19 -0
- package/dist/migrations/v007-media-folders.js.map +1 -0
- package/dist/migrations/v008-site-settings.d.ts +6 -0
- package/dist/migrations/v008-site-settings.d.ts.map +1 -0
- package/dist/migrations/v008-site-settings.js +17 -0
- package/dist/migrations/v008-site-settings.js.map +1 -0
- package/dist/migrations/v009-seo-config.d.ts +12 -0
- package/dist/migrations/v009-seo-config.d.ts.map +1 -0
- package/dist/migrations/v009-seo-config.js +27 -0
- package/dist/migrations/v009-seo-config.js.map +1 -0
- package/dist/migrations/v010-content-live-version.d.ts +15 -0
- package/dist/migrations/v010-content-live-version.d.ts.map +1 -0
- package/dist/migrations/v010-content-live-version.js +40 -0
- package/dist/migrations/v010-content-live-version.js.map +1 -0
- package/dist/migrations/v011-media.d.ts +12 -0
- package/dist/migrations/v011-media.d.ts.map +1 -0
- package/dist/migrations/v011-media.js +43 -0
- package/dist/migrations/v011-media.js.map +1 -0
- package/dist/migrations/v012-page-cache.d.ts +12 -0
- package/dist/migrations/v012-page-cache.d.ts.map +1 -0
- package/dist/migrations/v012-page-cache.js +31 -0
- package/dist/migrations/v012-page-cache.js.map +1 -0
- package/dist/migrations/v013-content-contracts.d.ts +17 -0
- package/dist/migrations/v013-content-contracts.d.ts.map +1 -0
- package/dist/migrations/v013-content-contracts.js +41 -0
- package/dist/migrations/v013-content-contracts.js.map +1 -0
- package/dist/migrations/v014-content-manifest-commit.d.ts +7 -0
- package/dist/migrations/v014-content-manifest-commit.d.ts.map +1 -0
- package/dist/migrations/v014-content-manifest-commit.js +12 -0
- package/dist/migrations/v014-content-manifest-commit.js.map +1 -0
- package/dist/postgres-adapter.d.ts +71 -0
- package/dist/postgres-adapter.d.ts.map +1 -0
- package/dist/postgres-adapter.js +327 -0
- package/dist/postgres-adapter.js.map +1 -0
- package/dist/postgres-checkpoints.d.ts +20 -0
- package/dist/postgres-checkpoints.d.ts.map +1 -0
- package/dist/postgres-checkpoints.js +109 -0
- package/dist/postgres-checkpoints.js.map +1 -0
- package/dist/postgres-lock-adapter.d.ts +12 -0
- package/dist/postgres-lock-adapter.d.ts.map +1 -0
- package/dist/postgres-lock-adapter.js +62 -0
- package/dist/postgres-lock-adapter.js.map +1 -0
- package/dist/postgres-media-adapter.d.ts +28 -0
- package/dist/postgres-media-adapter.d.ts.map +1 -0
- package/dist/postgres-media-adapter.js +167 -0
- package/dist/postgres-media-adapter.js.map +1 -0
- package/dist/postgres-media-folder-adapter.d.ts +12 -0
- package/dist/postgres-media-folder-adapter.d.ts.map +1 -0
- package/dist/postgres-media-folder-adapter.js +60 -0
- package/dist/postgres-media-folder-adapter.js.map +1 -0
- package/dist/postgres-page-cache-store.d.ts +23 -0
- package/dist/postgres-page-cache-store.d.ts.map +1 -0
- package/dist/postgres-page-cache-store.js +80 -0
- package/dist/postgres-page-cache-store.js.map +1 -0
- package/dist/postgres-retention-adapter.d.ts +14 -0
- package/dist/postgres-retention-adapter.d.ts.map +1 -0
- package/dist/postgres-retention-adapter.js +61 -0
- package/dist/postgres-retention-adapter.js.map +1 -0
- package/dist/postgres-seo-config-adapter.d.ts +14 -0
- package/dist/postgres-seo-config-adapter.d.ts.map +1 -0
- package/dist/postgres-seo-config-adapter.js +59 -0
- package/dist/postgres-seo-config-adapter.js.map +1 -0
- package/dist/postgres-site-settings-adapter.d.ts +11 -0
- package/dist/postgres-site-settings-adapter.d.ts.map +1 -0
- package/dist/postgres-site-settings-adapter.js +30 -0
- package/dist/postgres-site-settings-adapter.js.map +1 -0
- package/dist/postgres-webhook-delivery-adapter.d.ts +27 -0
- package/dist/postgres-webhook-delivery-adapter.d.ts.map +1 -0
- package/dist/postgres-webhook-delivery-adapter.js +99 -0
- package/dist/postgres-webhook-delivery-adapter.js.map +1 -0
- package/dist/row-mapping.d.ts +40 -0
- package/dist/row-mapping.d.ts.map +1 -0
- package/dist/row-mapping.js +49 -0
- package/dist/row-mapping.js.map +1 -0
- package/package.json +39 -3
- package/README.md +0 -3
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PostgresMigration } from '../migration-runner.js';
|
|
2
|
+
/**
|
|
3
|
+
* V010: live-version pointer on content rows.
|
|
4
|
+
*
|
|
5
|
+
* Every version row records `live_version` — the version of its document
|
|
6
|
+
* that is live (published) as of that row, or NULL when nothing is live. The
|
|
7
|
+
* document's live version is the current row's `live_version`, so a draft
|
|
8
|
+
* saved on top of a published page leaves the page live, and restoring
|
|
9
|
+
* `is_current` (checkpoints) restores the live version with it.
|
|
10
|
+
*
|
|
11
|
+
* Backfill: the latest published version at or before each row, unless a
|
|
12
|
+
* deletion lies between the two. Tombstones get NULL.
|
|
13
|
+
*/
|
|
14
|
+
export declare const v010ContentLiveVersion: PostgresMigration;
|
|
15
|
+
//# sourceMappingURL=v010-content-live-version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v010-content-live-version.d.ts","sourceRoot":"","sources":["../../src/migrations/v010-content-live-version.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,EAAE,iBA0BpC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V010: live-version pointer on content rows.
|
|
3
|
+
*
|
|
4
|
+
* Every version row records `live_version` — the version of its document
|
|
5
|
+
* that is live (published) as of that row, or NULL when nothing is live. The
|
|
6
|
+
* document's live version is the current row's `live_version`, so a draft
|
|
7
|
+
* saved on top of a published page leaves the page live, and restoring
|
|
8
|
+
* `is_current` (checkpoints) restores the live version with it.
|
|
9
|
+
*
|
|
10
|
+
* Backfill: the latest published version at or before each row, unless a
|
|
11
|
+
* deletion lies between the two. Tombstones get NULL.
|
|
12
|
+
*/
|
|
13
|
+
export const v010ContentLiveVersion = {
|
|
14
|
+
version: 10,
|
|
15
|
+
name: 'content_live_version',
|
|
16
|
+
apply: async (sql) => {
|
|
17
|
+
await sql.unsafe('ALTER TABLE content ADD COLUMN live_version INTEGER');
|
|
18
|
+
await sql.unsafe(`
|
|
19
|
+
UPDATE content c SET live_version = (
|
|
20
|
+
SELECT MAX(p.version) FROM content p
|
|
21
|
+
WHERE p.collection = c.collection
|
|
22
|
+
AND p.slug = c.slug
|
|
23
|
+
AND p.locale = c.locale
|
|
24
|
+
AND p.status = 'published'
|
|
25
|
+
AND p.version <= c.version
|
|
26
|
+
AND NOT EXISTS (
|
|
27
|
+
SELECT 1 FROM content d
|
|
28
|
+
WHERE d.collection = c.collection
|
|
29
|
+
AND d.slug = c.slug
|
|
30
|
+
AND d.locale = c.locale
|
|
31
|
+
AND d.status = 'deleted'
|
|
32
|
+
AND d.version > p.version
|
|
33
|
+
AND d.version <= c.version
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
WHERE c.status <> 'deleted'
|
|
37
|
+
`);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=v010-content-live-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v010-content-live-version.js","sourceRoot":"","sources":["../../src/migrations/v010-content-live-version.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAsB;IACvD,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,sBAAsB;IAC5B,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,GAAG,CAAC,MAAM,CAAC,qDAAqD,CAAC,CAAA;QACvE,MAAM,GAAG,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;KAmBhB,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PostgresMigration } from '../migration-runner.js';
|
|
2
|
+
/**
|
|
3
|
+
* V011: Versioned media metadata.
|
|
4
|
+
*
|
|
5
|
+
* One row per version of a media item; the current version has
|
|
6
|
+
* `is_current = TRUE`, and a delete appends a tombstone with `deleted_at`
|
|
7
|
+
* set. `storage_key` is the object key in the configured file store, or NULL
|
|
8
|
+
* for a registered external URL. `size` is INTEGER so the driver returns a
|
|
9
|
+
* number, not a bigint string.
|
|
10
|
+
*/
|
|
11
|
+
export declare const v011Media: PostgresMigration;
|
|
12
|
+
//# sourceMappingURL=v011-media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v011-media.d.ts","sourceRoot":"","sources":["../../src/migrations/v011-media.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,EAAE,iBAgCvB,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V011: Versioned media metadata.
|
|
3
|
+
*
|
|
4
|
+
* One row per version of a media item; the current version has
|
|
5
|
+
* `is_current = TRUE`, and a delete appends a tombstone with `deleted_at`
|
|
6
|
+
* set. `storage_key` is the object key in the configured file store, or NULL
|
|
7
|
+
* for a registered external URL. `size` is INTEGER so the driver returns a
|
|
8
|
+
* number, not a bigint string.
|
|
9
|
+
*/
|
|
10
|
+
export const v011Media = {
|
|
11
|
+
version: 11,
|
|
12
|
+
name: 'media',
|
|
13
|
+
apply: async (sql) => {
|
|
14
|
+
await sql.unsafe(`
|
|
15
|
+
CREATE TABLE media (
|
|
16
|
+
row_id TEXT PRIMARY KEY,
|
|
17
|
+
id TEXT NOT NULL,
|
|
18
|
+
version INTEGER NOT NULL,
|
|
19
|
+
is_current BOOLEAN NOT NULL DEFAULT TRUE,
|
|
20
|
+
filename TEXT NOT NULL,
|
|
21
|
+
storage_key TEXT,
|
|
22
|
+
url TEXT NOT NULL,
|
|
23
|
+
alt_text TEXT NOT NULL DEFAULT '',
|
|
24
|
+
mime_type TEXT NOT NULL,
|
|
25
|
+
size INTEGER NOT NULL,
|
|
26
|
+
width INTEGER,
|
|
27
|
+
height INTEGER,
|
|
28
|
+
folder TEXT,
|
|
29
|
+
tags JSONB NOT NULL DEFAULT '[]',
|
|
30
|
+
crop JSONB,
|
|
31
|
+
hotspot JSONB,
|
|
32
|
+
changed_by TEXT,
|
|
33
|
+
deleted_at TIMESTAMPTZ,
|
|
34
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
35
|
+
UNIQUE (id, version)
|
|
36
|
+
)
|
|
37
|
+
`);
|
|
38
|
+
await sql.unsafe('CREATE INDEX idx_media_current ON media(id) WHERE is_current');
|
|
39
|
+
await sql.unsafe('CREATE INDEX idx_media_folder ON media(folder) WHERE is_current');
|
|
40
|
+
await sql.unsafe('CREATE INDEX idx_media_filename ON media(filename) WHERE is_current');
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=v011-media.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v011-media.js","sourceRoot":"","sources":["../../src/migrations/v011-media.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAsB;IAC1C,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,GAAG,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;KAuBhB,CAAC,CAAA;QACF,MAAM,GAAG,CAAC,MAAM,CAAC,8DAA8D,CAAC,CAAA;QAChF,MAAM,GAAG,CAAC,MAAM,CAAC,iEAAiE,CAAC,CAAA;QACnF,MAAM,GAAG,CAAC,MAAM,CAAC,qEAAqE,CAAC,CAAA;IACzF,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PostgresMigration } from '../migration-runner.js';
|
|
2
|
+
/**
|
|
3
|
+
* V012: shared page cache — rendered pages and fetch results, and the latest
|
|
4
|
+
* stale and expire mark per cache tag, shared by every instance of a site.
|
|
5
|
+
*
|
|
6
|
+
* `page_cache_entries.value` holds the encoded value (JSON text kept verbatim,
|
|
7
|
+
* binary leaves base64 — `encodePageCacheValue` in `@krantho/persistence`);
|
|
8
|
+
* `tags` is replaced on every write. Timestamps are epoch milliseconds on the
|
|
9
|
+
* database clock. `page_cache_tags.expired_at` is NULL until a tag is first expired.
|
|
10
|
+
*/
|
|
11
|
+
export declare const v012PageCache: PostgresMigration;
|
|
12
|
+
//# sourceMappingURL=v012-page-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v012-page-cache.d.ts","sourceRoot":"","sources":["../../src/migrations/v012-page-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,EAAE,iBAoB3B,CAAA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V012: shared page cache — rendered pages and fetch results, and the latest
|
|
3
|
+
* stale and expire mark per cache tag, shared by every instance of a site.
|
|
4
|
+
*
|
|
5
|
+
* `page_cache_entries.value` holds the encoded value (JSON text kept verbatim,
|
|
6
|
+
* binary leaves base64 — `encodePageCacheValue` in `@krantho/persistence`);
|
|
7
|
+
* `tags` is replaced on every write. Timestamps are epoch milliseconds on the
|
|
8
|
+
* database clock. `page_cache_tags.expired_at` is NULL until a tag is first expired.
|
|
9
|
+
*/
|
|
10
|
+
export const v012PageCache = {
|
|
11
|
+
version: 12,
|
|
12
|
+
name: 'page_cache',
|
|
13
|
+
apply: async (sql) => {
|
|
14
|
+
await sql.unsafe(`
|
|
15
|
+
CREATE TABLE page_cache_entries (
|
|
16
|
+
key TEXT PRIMARY KEY,
|
|
17
|
+
value TEXT NOT NULL,
|
|
18
|
+
tags TEXT[] NOT NULL DEFAULT '{}',
|
|
19
|
+
last_modified BIGINT NOT NULL
|
|
20
|
+
)
|
|
21
|
+
`);
|
|
22
|
+
await sql.unsafe(`
|
|
23
|
+
CREATE TABLE page_cache_tags (
|
|
24
|
+
tag TEXT PRIMARY KEY,
|
|
25
|
+
stale_at BIGINT NOT NULL,
|
|
26
|
+
expired_at BIGINT
|
|
27
|
+
)
|
|
28
|
+
`);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=v012-page-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v012-page-cache.js","sourceRoot":"","sources":["../../src/migrations/v012-page-cache.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,YAAY;IAClB,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,GAAG,CAAC,MAAM,CAAC;;;;;;;KAOhB,CAAC,CAAA;QACF,MAAM,GAAG,CAAC,MAAM,CAAC;;;;;;KAMhB,CAAC,CAAA;IACJ,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PostgresMigration } from '../migration-runner.js';
|
|
2
|
+
/**
|
|
3
|
+
* V013: content contracts — authored metadata on content rows, metadata groups
|
|
4
|
+
* on runtime schemas, and the locale of a repository import conflict.
|
|
5
|
+
*
|
|
6
|
+
* `content.authored` holds `{ metadata, contract, defaults, repositoryBasis }`
|
|
7
|
+
* (`AuthoredMetadata` in `@krantho/persistence`); rows written before it have
|
|
8
|
+
* no metadata and no contract. A conflict recorded before conflicts had a
|
|
9
|
+
* locale takes the locale of the document's first version.
|
|
10
|
+
*
|
|
11
|
+
* A document's own SEO moves from `seo_config` into its metadata: every version
|
|
12
|
+
* of the document gets the config as `metadata.seo`, as it applied to all of
|
|
13
|
+
* them before, and the `doc:` rows are removed. A config that is not an object
|
|
14
|
+
* (null, or text that does not parse) is left in place, and nothing is lost.
|
|
15
|
+
*/
|
|
16
|
+
export declare const v013ContentContracts: PostgresMigration;
|
|
17
|
+
//# sourceMappingURL=v013-content-contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v013-content-contracts.d.ts","sourceRoot":"","sources":["../../src/migrations/v013-content-contracts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,EAAE,iBA+BlC,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { documentSeoRow } from '@krantho/persistence';
|
|
2
|
+
/**
|
|
3
|
+
* V013: content contracts — authored metadata on content rows, metadata groups
|
|
4
|
+
* on runtime schemas, and the locale of a repository import conflict.
|
|
5
|
+
*
|
|
6
|
+
* `content.authored` holds `{ metadata, contract, defaults, repositoryBasis }`
|
|
7
|
+
* (`AuthoredMetadata` in `@krantho/persistence`); rows written before it have
|
|
8
|
+
* no metadata and no contract. A conflict recorded before conflicts had a
|
|
9
|
+
* locale takes the locale of the document's first version.
|
|
10
|
+
*
|
|
11
|
+
* A document's own SEO moves from `seo_config` into its metadata: every version
|
|
12
|
+
* of the document gets the config as `metadata.seo`, as it applied to all of
|
|
13
|
+
* them before, and the `doc:` rows are removed. A config that is not an object
|
|
14
|
+
* (null, or text that does not parse) is left in place, and nothing is lost.
|
|
15
|
+
*/
|
|
16
|
+
export const v013ContentContracts = {
|
|
17
|
+
version: 13,
|
|
18
|
+
name: 'content_contracts',
|
|
19
|
+
apply: async (sql) => {
|
|
20
|
+
await sql.unsafe(`ALTER TABLE content ADD COLUMN authored JSONB NOT NULL DEFAULT '{"metadata":{},"contract":null,"defaults":[],"repositoryBasis":null}'`);
|
|
21
|
+
await sql.unsafe(`ALTER TABLE collection_schemas ADD COLUMN metadata_groups JSONB NOT NULL DEFAULT '[]'`);
|
|
22
|
+
await sql.unsafe(`ALTER TABLE content_migration_conflicts ADD COLUMN locale TEXT NOT NULL DEFAULT ''`);
|
|
23
|
+
await sql.unsafe(`
|
|
24
|
+
UPDATE content_migration_conflicts m SET locale = COALESCE((
|
|
25
|
+
SELECT c.locale FROM content c
|
|
26
|
+
WHERE c.collection = m.collection AND c.slug = m.slug
|
|
27
|
+
ORDER BY c.created_at, c.version LIMIT 1
|
|
28
|
+
), '')
|
|
29
|
+
`);
|
|
30
|
+
const rows = (await sql.unsafe(`SELECT id, config FROM seo_config WHERE scope = 'document'`));
|
|
31
|
+
for (const row of rows) {
|
|
32
|
+
const moved = documentSeoRow(row.id, row.config);
|
|
33
|
+
if (!moved)
|
|
34
|
+
continue;
|
|
35
|
+
await sql `UPDATE content SET authored = jsonb_set(authored, '{metadata,seo}', ${sql.json(moved.config)})
|
|
36
|
+
WHERE collection = ${moved.collection} AND slug = ${moved.slug}`;
|
|
37
|
+
await sql.unsafe('DELETE FROM seo_config WHERE id = $1', [row.id]);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=v013-content-contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v013-content-contracts.js","sourceRoot":"","sources":["../../src/migrations/v013-content-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAsB;IACrD,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,GAAG,CAAC,MAAM,CACd,uIAAuI,CACxI,CAAA;QACD,MAAM,GAAG,CAAC,MAAM,CACd,uFAAuF,CACxF,CAAA;QACD,MAAM,GAAG,CAAC,MAAM,CACd,oFAAoF,CACrF,CAAA;QACD,MAAM,GAAG,CAAC,MAAM,CAAC;;;;;;KAMhB,CAAC,CAAA;QACF,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,CAC5B,4DAA4D,CAC7D,CAA2C,CAAA;QAC5C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,KAAK,GAAG,cAAc,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;YAChD,IAAI,CAAC,KAAK;gBAAE,SAAQ;YACpB,MAAM,GAAG,CAAA,uEAAuE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAe,CAAC;6BACxF,KAAK,CAAC,UAAU,eAAe,KAAK,CAAC,IAAI,EAAE,CAAA;YAClE,MAAM,GAAG,CAAC,MAAM,CAAC,sCAAsC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;QACpE,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PostgresMigration } from '../migration-runner.js';
|
|
2
|
+
/**
|
|
3
|
+
* V014: the git commit each content import came from. `content_manifest.repo_commit` is NULL
|
|
4
|
+
* for an import whose build did not record one.
|
|
5
|
+
*/
|
|
6
|
+
export declare const v014ContentManifestCommit: PostgresMigration;
|
|
7
|
+
//# sourceMappingURL=v014-content-manifest-commit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v014-content-manifest-commit.d.ts","sourceRoot":"","sources":["../../src/migrations/v014-content-manifest-commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,iBAMvC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V014: the git commit each content import came from. `content_manifest.repo_commit` is NULL
|
|
3
|
+
* for an import whose build did not record one.
|
|
4
|
+
*/
|
|
5
|
+
export const v014ContentManifestCommit = {
|
|
6
|
+
version: 14,
|
|
7
|
+
name: 'content_manifest_commit',
|
|
8
|
+
apply: async (sql) => {
|
|
9
|
+
await sql.unsafe('ALTER TABLE content_manifest ADD COLUMN repo_commit TEXT');
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=v014-content-manifest-commit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v014-content-manifest-commit.js","sourceRoot":"","sources":["../../src/migrations/v014-content-manifest-commit.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAsB;IAC1D,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,yBAAyB;IAC/B,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACnB,MAAM,GAAG,CAAC,MAAM,CAAC,0DAA0D,CAAC,CAAA;IAC9E,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type ContentMetadata } from '@krantho/core';
|
|
2
|
+
import type { AuthoredMetadata, ContentDocument, ContentQuery, DocumentMeta, IPersistenceAdapter, Publication, QueryPage, QueryProjection, RuntimeSchemaDefinition, WriteContentData } from '@krantho/persistence';
|
|
3
|
+
import type { Sql } from 'postgres';
|
|
4
|
+
/** Status written when the caller supplies none, per write path */
|
|
5
|
+
export interface PostgresDefaultStatus {
|
|
6
|
+
/** Documents upserted from a markdown file whose frontmatter has no status */
|
|
7
|
+
filesystem: string;
|
|
8
|
+
}
|
|
9
|
+
/** Construction options for {@link PostgresAdapter} */
|
|
10
|
+
export interface PostgresAdapterOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Locale of every read and write that names none: the site's default locale,
|
|
13
|
+
* `site.defaultLocale` in the krantho configuration.
|
|
14
|
+
*/
|
|
15
|
+
defaultLocale: string;
|
|
16
|
+
defaultStatus?: Partial<PostgresDefaultStatus> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Status default used when a file declares none.
|
|
20
|
+
*
|
|
21
|
+
* A deployment sets it through `content.defaultStatus.filesystem` in the
|
|
22
|
+
* krantho configuration tree; the server passes the resolved value down. This
|
|
23
|
+
* literal is the standalone-library fallback and mirrors that tree's default.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_POSTGRES_STATUS: PostgresDefaultStatus;
|
|
26
|
+
export declare class PostgresAdapter implements IPersistenceAdapter {
|
|
27
|
+
private readonly sql;
|
|
28
|
+
private readonly defaultStatus;
|
|
29
|
+
private readonly defaultLocale;
|
|
30
|
+
private initialization;
|
|
31
|
+
constructor(sql: Sql, options: PostgresAdapterOptions);
|
|
32
|
+
static create(sql: Sql, options: PostgresAdapterOptions): Promise<PostgresAdapter>;
|
|
33
|
+
/**
|
|
34
|
+
* Run migrations once per instance. Concurrent callers share the in-flight
|
|
35
|
+
* run; a failed run is dropped so the next call retries it.
|
|
36
|
+
*/
|
|
37
|
+
private ensureInitialized;
|
|
38
|
+
exists(slug: string): Promise<boolean>;
|
|
39
|
+
read(slug: string): Promise<string>;
|
|
40
|
+
getMetadata(slug: string): Promise<Pick<ContentMetadata, 'size' | 'lastModified'>>;
|
|
41
|
+
listSlugs(): Promise<string[]>;
|
|
42
|
+
writeContent(data: WriteContentData, changedBy?: string | undefined): Promise<void>;
|
|
43
|
+
deleteContent(collection: string, slug: string, locale?: string | undefined, changedBy?: string | undefined): Promise<void>;
|
|
44
|
+
getContent(collection: string, slug: string, locale?: string | undefined): Promise<ContentDocument | null>;
|
|
45
|
+
getPublished(collection: string, slug: string, locale?: string | undefined): Promise<ContentDocument | null>;
|
|
46
|
+
query<P extends QueryProjection>(spec: ContentQuery<P>): Promise<QueryPage<P>>;
|
|
47
|
+
listVersions(collection: string, slug: string, locale?: string | undefined): Promise<DocumentMeta[]>;
|
|
48
|
+
getVersion(collection: string, slug: string, version: number, locale?: string | undefined): Promise<ContentDocument | null>;
|
|
49
|
+
/**
|
|
50
|
+
* Import a filesystem content item — creates a new version if content changed.
|
|
51
|
+
* `modifiedAt` (ISO 8601) dates the version when the file last changed, such as
|
|
52
|
+
* its last git commit; without it the version is dated now.
|
|
53
|
+
*/
|
|
54
|
+
upsertFromFile(collection: string, slug: string, fields: Record<string, unknown>, body: string, html: string, sections: Record<string, string>, filePath: string, locale?: string | undefined, modifiedAt?: string | undefined, authored?: (Partial<AuthoredMetadata> & {
|
|
55
|
+
publication: Publication | undefined;
|
|
56
|
+
expectedVersion?: number | undefined;
|
|
57
|
+
}) | undefined): Promise<void>;
|
|
58
|
+
/** Restore content to a specific version — a save: a new current version from the old one, the live version kept */
|
|
59
|
+
restoreVersion(collection: string, slug: string, version: number, changedBy?: string | undefined, locale?: string | undefined): Promise<boolean>;
|
|
60
|
+
getRuntimeSchema(collection: string): Promise<RuntimeSchemaDefinition | null>;
|
|
61
|
+
saveRuntimeSchema(collection: string, schema: RuntimeSchemaDefinition, changedBy?: string | undefined): Promise<void>;
|
|
62
|
+
/** Close the database connection */
|
|
63
|
+
close(): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Core append-only write: flip current, insert the new version. Its live
|
|
66
|
+
* version follows the write's publication (a save keeps it) and its stored
|
|
67
|
+
* status follows the live version.
|
|
68
|
+
*/
|
|
69
|
+
private appendVersion;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=postgres-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
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