emdash 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/{adapters-DoNJiveC.d.mts → adapters-BktHA7EO.d.mts} +1 -1
- package/dist/{adapters-DoNJiveC.d.mts.map → adapters-BktHA7EO.d.mts.map} +1 -1
- package/dist/{apply-BzltprvY.mjs → apply-UsrFuO7l.mjs} +156 -254
- package/dist/apply-UsrFuO7l.mjs.map +1 -0
- package/dist/astro/index.d.mts +6 -6
- package/dist/astro/index.mjs +10 -2
- package/dist/astro/index.mjs.map +1 -1
- package/dist/astro/middleware/auth.d.mts +5 -5
- package/dist/astro/middleware/auth.mjs +5 -5
- package/dist/astro/middleware/redirect.mjs +5 -5
- package/dist/astro/middleware/request-context.mjs +4 -4
- package/dist/astro/middleware/setup.mjs +1 -1
- package/dist/astro/middleware.mjs +35 -34
- package/dist/astro/middleware.mjs.map +1 -1
- package/dist/astro/types.d.mts +8 -9
- package/dist/astro/types.d.mts.map +1 -1
- package/dist/{base64-BRICGH2l.mjs → base64-MBPo9ozB.mjs} +1 -1
- package/dist/{base64-BRICGH2l.mjs.map → base64-MBPo9ozB.mjs.map} +1 -1
- package/dist/{byline-BSaNL1w7.mjs → byline-C3vnhIpU.mjs} +4 -4
- package/dist/{byline-BSaNL1w7.mjs.map → byline-C3vnhIpU.mjs.map} +1 -1
- package/dist/{bylines-CvJ3PYz2.mjs → bylines-esI7ioa9.mjs} +5 -5
- package/dist/{bylines-CvJ3PYz2.mjs.map → bylines-esI7ioa9.mjs.map} +1 -1
- package/dist/{cache-C6N_hhN7.mjs → cache-fTzxgMFJ.mjs} +3 -3
- package/dist/{cache-C6N_hhN7.mjs.map → cache-fTzxgMFJ.mjs.map} +1 -1
- package/dist/{chunks-NBQVDOci.mjs → chunks-Da2-b-oA.mjs} +2 -2
- package/dist/{chunks-NBQVDOci.mjs.map → chunks-Da2-b-oA.mjs.map} +1 -1
- package/dist/cli/index.mjs +251 -79
- package/dist/cli/index.mjs.map +1 -1
- package/dist/client/cf-access.d.mts +1 -1
- package/dist/client/index.d.mts +1 -1
- package/dist/client/index.mjs +1 -1
- package/dist/{config-BI0V3ICQ.mjs → config-CVssduLe.mjs} +1 -1
- package/dist/{config-BI0V3ICQ.mjs.map → config-CVssduLe.mjs.map} +1 -1
- package/dist/{content-8lOYF0pr.mjs → content-C7G4QXkK.mjs} +14 -3
- package/dist/content-C7G4QXkK.mjs.map +1 -0
- package/dist/db/index.d.mts +3 -3
- package/dist/db/index.mjs +1 -1
- package/dist/db/libsql.d.mts +1 -1
- package/dist/db/postgres.d.mts +1 -1
- package/dist/db/sqlite.d.mts +1 -1
- package/dist/{db-errors-WRezodiz.mjs → db-errors-B7P2pSCn.mjs} +1 -1
- package/dist/{db-errors-WRezodiz.mjs.map → db-errors-B7P2pSCn.mjs.map} +1 -1
- package/dist/{default-D8ksjWhO.mjs → default-pHuz9WF6.mjs} +1 -1
- package/dist/{default-D8ksjWhO.mjs.map → default-pHuz9WF6.mjs.map} +1 -1
- package/dist/{error-D_-tqP-I.mjs → error-DqnRMM5z.mjs} +1 -1
- package/dist/{error-D_-tqP-I.mjs.map → error-DqnRMM5z.mjs.map} +1 -1
- package/dist/{index-BFRaVcD6.d.mts → index-DjPMOfO0.d.mts} +82 -67
- package/dist/index-DjPMOfO0.d.mts.map +1 -0
- package/dist/index.d.mts +10 -10
- package/dist/index.mjs +28 -27
- package/dist/{load-DDqMMvZL.mjs → load-sXRuM7Us.mjs} +2 -2
- package/dist/{load-DDqMMvZL.mjs.map → load-sXRuM7Us.mjs.map} +1 -1
- package/dist/{loader-CKLbBnhK.mjs → loader-Bx2_9-5e.mjs} +31 -6
- package/dist/loader-Bx2_9-5e.mjs.map +1 -0
- package/dist/{manifest-schema-DqWNC3lM.mjs → manifest-schema-CXAbd1vH.mjs} +1 -1
- package/dist/{manifest-schema-DqWNC3lM.mjs.map → manifest-schema-CXAbd1vH.mjs.map} +1 -1
- package/dist/media/index.d.mts +1 -1
- package/dist/media/index.mjs +1 -1
- package/dist/media/local-runtime.d.mts +7 -7
- package/dist/media/local-runtime.mjs +3 -3
- package/dist/{media-BW32b4gi.mjs → media-D8FbNsl0.mjs} +2 -2
- package/dist/{media-BW32b4gi.mjs.map → media-D8FbNsl0.mjs.map} +1 -1
- package/dist/{mode-ier8jbBk.mjs → mode-YhqNVef_.mjs} +1 -1
- package/dist/{mode-ier8jbBk.mjs.map → mode-YhqNVef_.mjs.map} +1 -1
- package/dist/{options-BVp3UsTS.mjs → options-nPxWnrya.mjs} +1 -1
- package/dist/{options-BVp3UsTS.mjs.map → options-nPxWnrya.mjs.map} +1 -1
- package/dist/page/index.d.mts +2 -2
- package/dist/{patterns-CrCYkMBb.mjs → patterns-DsUZ4uxI.mjs} +1 -1
- package/dist/{patterns-CrCYkMBb.mjs.map → patterns-DsUZ4uxI.mjs.map} +1 -1
- package/dist/{placeholder-BE4o_2dc.d.mts → placeholder-CDPtkelt.d.mts} +1 -1
- package/dist/{placeholder-BE4o_2dc.d.mts.map → placeholder-CDPtkelt.d.mts.map} +1 -1
- package/dist/{placeholder-CIJejMlK.mjs → placeholder-Ci0RLeCk.mjs} +1 -1
- package/dist/{placeholder-CIJejMlK.mjs.map → placeholder-Ci0RLeCk.mjs.map} +1 -1
- package/dist/plugins/adapt-sandbox-entry.d.mts +5 -5
- package/dist/plugins/adapt-sandbox-entry.mjs +2 -2
- package/dist/{public-url-DByxYjUw.mjs → public-url-B1AxbbbQ.mjs} +1 -1
- package/dist/{public-url-DByxYjUw.mjs.map → public-url-B1AxbbbQ.mjs.map} +1 -1
- package/dist/{query-Cg9ZKRQ0.mjs → query-Bo-msrmu.mjs} +13 -13
- package/dist/{query-Cg9ZKRQ0.mjs.map → query-Bo-msrmu.mjs.map} +1 -1
- package/dist/{redirect-BhUBKRc1.mjs → redirect-C5H7VGIX.mjs} +3 -3
- package/dist/{redirect-BhUBKRc1.mjs.map → redirect-C5H7VGIX.mjs.map} +1 -1
- package/dist/{registry-Dw70ChxB.mjs → registry-Beb7wxFc.mjs} +5 -5
- package/dist/{registry-Dw70ChxB.mjs.map → registry-Beb7wxFc.mjs.map} +1 -1
- package/dist/{request-cache-B-bmkipQ.mjs → request-cache-C-tIpYIw.mjs} +1 -1
- package/dist/{request-cache-B-bmkipQ.mjs.map → request-cache-C-tIpYIw.mjs.map} +1 -1
- package/dist/{runner-Bnoj7vjK.d.mts → runner-Clwe4Mme.d.mts} +2 -2
- package/dist/{runner-Bnoj7vjK.d.mts.map → runner-Clwe4Mme.d.mts.map} +1 -1
- package/dist/{runner-C7ADox5q.mjs → runner-DMnlIkh4.mjs} +433 -138
- package/dist/runner-DMnlIkh4.mjs.map +1 -0
- package/dist/runtime.d.mts +6 -6
- package/dist/runtime.mjs +3 -3
- package/dist/{search-dOGEccMa.mjs → search-DkN-BqsS.mjs} +164 -92
- package/dist/search-DkN-BqsS.mjs.map +1 -0
- package/dist/{secrets-CW3reAnU.mjs → secrets-CZ8rxLX3.mjs} +3 -3
- package/dist/{secrets-CW3reAnU.mjs.map → secrets-CZ8rxLX3.mjs.map} +1 -1
- package/dist/seed/index.d.mts +2 -2
- package/dist/seed/index.mjs +15 -14
- package/dist/seo/index.d.mts +1 -1
- package/dist/storage/local.d.mts +1 -1
- package/dist/storage/local.mjs +1 -1
- package/dist/storage/s3.d.mts +1 -1
- package/dist/storage/s3.mjs +1 -1
- package/dist/taxonomies-CTtewrSQ.mjs +407 -0
- package/dist/taxonomies-CTtewrSQ.mjs.map +1 -0
- package/dist/taxonomy-DSxx2K2L.mjs +218 -0
- package/dist/taxonomy-DSxx2K2L.mjs.map +1 -0
- package/dist/{tokens-D7zMmWi2.mjs → tokens-CyRDPVW2.mjs} +2 -2
- package/dist/{tokens-D7zMmWi2.mjs.map → tokens-CyRDPVW2.mjs.map} +1 -1
- package/dist/{transaction-Cn2rjY78.mjs → transaction-D44LBXvU.mjs} +1 -1
- package/dist/{transaction-Cn2rjY78.mjs.map → transaction-D44LBXvU.mjs.map} +1 -1
- package/dist/{transport-DNEfeMaU.d.mts → transport-DX_5rpsq.d.mts} +1 -1
- package/dist/{transport-DNEfeMaU.d.mts.map → transport-DX_5rpsq.d.mts.map} +1 -1
- package/dist/{transport-BeMCmin1.mjs → transport-xpzIjCIB.mjs} +1 -1
- package/dist/{transport-BeMCmin1.mjs.map → transport-xpzIjCIB.mjs.map} +1 -1
- package/dist/{types-CRxNbK-Z.mjs → types-BIgulNsW.mjs} +2 -2
- package/dist/{types-CRxNbK-Z.mjs.map → types-BIgulNsW.mjs.map} +1 -1
- package/dist/{types-CJsYGpco.d.mts → types-B_CXXnzh.d.mts} +1 -1
- package/dist/{types-CJsYGpco.d.mts.map → types-B_CXXnzh.d.mts.map} +1 -1
- package/dist/{types-M78DQ1lx.d.mts → types-C-aFbqmA.d.mts} +1 -1
- package/dist/{types-M78DQ1lx.d.mts.map → types-C-aFbqmA.d.mts.map} +1 -1
- package/dist/{types-4fVtCIm0.mjs → types-CoO6mpV3.mjs} +1 -1
- package/dist/{types-4fVtCIm0.mjs.map → types-CoO6mpV3.mjs.map} +1 -1
- package/dist/{types-BuBIptGk.d.mts → types-D19uBYWn.d.mts} +149 -4
- package/dist/types-D19uBYWn.d.mts.map +1 -0
- package/dist/{types-BSyXeCFW.d.mts → types-Dl1fgFjn.d.mts} +1 -1
- package/dist/{types-BSyXeCFW.d.mts.map → types-Dl1fgFjn.d.mts.map} +1 -1
- package/dist/{types-CrtWgIvl.d.mts → types-Dtx1mSMX.d.mts} +9 -1
- package/dist/types-Dtx1mSMX.d.mts.map +1 -0
- package/dist/{types-CIOg5AR8.mjs → types-Eg829jj9.mjs} +1 -1
- package/dist/{types-CIOg5AR8.mjs.map → types-Eg829jj9.mjs.map} +1 -1
- package/dist/{types-CDbKp7ND.mjs → types-K-EkEQCI.mjs} +1 -1
- package/dist/{types-CDbKp7ND.mjs.map → types-K-EkEQCI.mjs.map} +1 -1
- package/dist/{validate-Baqf0slj.mjs → validate-CBIbxM3L.mjs} +14 -10
- package/dist/validate-CBIbxM3L.mjs.map +1 -0
- package/dist/{validate-BfQh_C_y.d.mts → validate-DHGwADqO.d.mts} +18 -5
- package/dist/validate-DHGwADqO.d.mts.map +1 -0
- package/dist/{validation-BfEI7tNe.mjs → validation-B1NYiEos.mjs} +5 -5
- package/dist/{validation-BfEI7tNe.mjs.map → validation-B1NYiEos.mjs.map} +1 -1
- package/dist/version-CMD42IRC.mjs +7 -0
- package/dist/{version-DoxrVdYf.mjs.map → version-CMD42IRC.mjs.map} +1 -1
- package/dist/{zod-generator-CC0xNe_K.mjs → zod-generator-BNJDQBSZ.mjs} +8 -3
- package/dist/zod-generator-BNJDQBSZ.mjs.map +1 -0
- package/package.json +6 -6
- package/src/api/handlers/content.ts +11 -0
- package/src/api/handlers/dashboard.ts +29 -36
- package/src/api/handlers/menus.ts +256 -75
- package/src/api/handlers/taxonomies.ts +273 -97
- package/src/api/schemas/common.ts +7 -0
- package/src/api/schemas/menus.ts +23 -0
- package/src/api/schemas/taxonomies.ts +39 -0
- package/src/astro/integration/routes.ts +10 -0
- package/src/astro/routes/api/content/[collection]/[id]/permanent.ts +1 -1
- package/src/astro/routes/api/import/wordpress/rewrite-url-helpers.ts +196 -0
- package/src/astro/routes/api/import/wordpress/rewrite-urls.ts +9 -177
- package/src/astro/routes/api/menus/[name]/items.ts +16 -6
- package/src/astro/routes/api/menus/[name]/reorder.ts +8 -3
- package/src/astro/routes/api/menus/[name]/translations.ts +82 -0
- package/src/astro/routes/api/menus/[name].ts +19 -10
- package/src/astro/routes/api/menus/index.ts +9 -6
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug]/translations.ts +89 -0
- package/src/astro/routes/api/taxonomies/[name]/terms/[slug].ts +22 -22
- package/src/astro/routes/api/taxonomies/[name]/terms/index.ts +11 -14
- package/src/astro/routes/api/taxonomies/index.ts +9 -6
- package/src/cli/commands/export-seed.ts +82 -21
- package/src/cli/commands/plugin-init.ts +216 -90
- package/src/database/migrations/036_i18n_menus_and_taxonomies.ts +477 -0
- package/src/database/migrations/runner.ts +2 -0
- package/src/database/repositories/content.ts +11 -0
- package/src/database/repositories/taxonomy.ts +193 -89
- package/src/database/types.ts +10 -2
- package/src/i18n/resolve.ts +37 -0
- package/src/loader.ts +49 -2
- package/src/mcp/server.ts +77 -18
- package/src/menus/index.ts +143 -124
- package/src/menus/types.ts +15 -1
- package/src/schema/zod-generator.ts +12 -2
- package/src/seed/apply.ts +140 -54
- package/src/seed/types.ts +14 -1
- package/src/seed/validate.ts +27 -13
- package/src/taxonomies/index.ts +230 -213
- package/src/taxonomies/types.ts +10 -0
- package/dist/apply-BzltprvY.mjs.map +0 -1
- package/dist/content-8lOYF0pr.mjs.map +0 -1
- package/dist/index-BFRaVcD6.d.mts.map +0 -1
- package/dist/loader-CKLbBnhK.mjs.map +0 -1
- package/dist/runner-C7ADox5q.mjs.map +0 -1
- package/dist/search-dOGEccMa.mjs.map +0 -1
- package/dist/taxonomies-ZlRtD6AG.mjs +0 -315
- package/dist/taxonomies-ZlRtD6AG.mjs.map +0 -1
- package/dist/types-BuBIptGk.d.mts.map +0 -1
- package/dist/types-CrtWgIvl.d.mts.map +0 -1
- package/dist/validate-Baqf0slj.mjs.map +0 -1
- package/dist/validate-BfQh_C_y.d.mts.map +0 -1
- package/dist/version-DoxrVdYf.mjs +0 -7
- package/dist/zod-generator-CC0xNe_K.mjs.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { t as validateIdentifier } from "./validate-VPnKoIzW.mjs";
|
|
2
2
|
import { c as listTablesLike, i as currentTimestampValue, n as columnExists, o as isSqlite, r as currentTimestamp, t as binaryType } from "./dialect-helpers-BKCvISIQ.mjs";
|
|
3
|
+
import { n as getI18nConfig } from "./config-CVssduLe.mjs";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import { Migrator, sql } from "kysely";
|
|
5
6
|
|
|
@@ -22,8 +23,8 @@ var __exportAll = (all, no_symbols) => {
|
|
|
22
23
|
//#endregion
|
|
23
24
|
//#region src/database/migrations/001_initial.ts
|
|
24
25
|
var _001_initial_exports = /* @__PURE__ */ __exportAll({
|
|
25
|
-
down: () => down$
|
|
26
|
-
up: () => up$
|
|
26
|
+
down: () => down$34,
|
|
27
|
+
up: () => up$34
|
|
27
28
|
});
|
|
28
29
|
/**
|
|
29
30
|
* Initial schema migration
|
|
@@ -32,7 +33,7 @@ var _001_initial_exports = /* @__PURE__ */ __exportAll({
|
|
|
32
33
|
* by the SchemaRegistry when collections are added via the admin UI.
|
|
33
34
|
* This migration only creates system tables.
|
|
34
35
|
*/
|
|
35
|
-
async function up$
|
|
36
|
+
async function up$34(db) {
|
|
36
37
|
await db.schema.createTable("revisions").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("collection", "text", (col) => col.notNull()).addColumn("entry_id", "text", (col) => col.notNull()).addColumn("data", "text", (col) => col.notNull()).addColumn("author_id", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
37
38
|
await db.schema.createIndex("idx_revisions_entry").ifNotExists().on("revisions").columns(["collection", "entry_id"]).execute();
|
|
38
39
|
await db.schema.createTable("taxonomies").ifNotExists().addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("slug", "text", (col) => col.notNull()).addColumn("label", "text", (col) => col.notNull()).addColumn("parent_id", "text").addColumn("data", "text").addUniqueConstraint("taxonomies_name_slug_unique", ["name", "slug"]).addForeignKeyConstraint("taxonomies_parent_fk", ["parent_id"], "taxonomies", ["id"], (cb) => cb.onDelete("set null")).execute();
|
|
@@ -52,7 +53,7 @@ async function up$33(db) {
|
|
|
52
53
|
await db.schema.createIndex("idx_audit_action").ifNotExists().on("audit_logs").column("action").execute();
|
|
53
54
|
await db.schema.createIndex("idx_audit_timestamp").ifNotExists().on("audit_logs").column("timestamp").execute();
|
|
54
55
|
}
|
|
55
|
-
async function down$
|
|
56
|
+
async function down$34(db) {
|
|
56
57
|
await db.schema.dropTable("audit_logs").execute();
|
|
57
58
|
await db.schema.dropTable("options").execute();
|
|
58
59
|
await db.schema.dropTable("users").execute();
|
|
@@ -65,26 +66,26 @@ async function down$33(db) {
|
|
|
65
66
|
//#endregion
|
|
66
67
|
//#region src/database/migrations/002_media_status.ts
|
|
67
68
|
var _002_media_status_exports = /* @__PURE__ */ __exportAll({
|
|
68
|
-
down: () => down$
|
|
69
|
-
up: () => up$
|
|
69
|
+
down: () => down$33,
|
|
70
|
+
up: () => up$33
|
|
70
71
|
});
|
|
71
72
|
/**
|
|
72
73
|
* Add status column to media table for tracking upload state.
|
|
73
74
|
* Status values: 'pending' | 'ready' | 'failed'
|
|
74
75
|
*/
|
|
75
|
-
async function up$
|
|
76
|
+
async function up$33(db) {
|
|
76
77
|
await db.schema.alterTable("media").addColumn("status", "text", (col) => col.notNull().defaultTo("ready")).execute();
|
|
77
78
|
await db.schema.createIndex("idx_media_status").on("media").column("status").execute();
|
|
78
79
|
}
|
|
79
|
-
async function down$
|
|
80
|
+
async function down$33(db) {
|
|
80
81
|
await db.schema.dropIndex("idx_media_status").execute();
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
//#endregion
|
|
84
85
|
//#region src/database/migrations/003_schema_registry.ts
|
|
85
86
|
var _003_schema_registry_exports = /* @__PURE__ */ __exportAll({
|
|
86
|
-
down: () => down$
|
|
87
|
-
up: () => up$
|
|
87
|
+
down: () => down$32,
|
|
88
|
+
up: () => up$32
|
|
88
89
|
});
|
|
89
90
|
/**
|
|
90
91
|
* Migration: Schema Registry Tables
|
|
@@ -92,14 +93,14 @@ var _003_schema_registry_exports = /* @__PURE__ */ __exportAll({
|
|
|
92
93
|
* Creates the schema registry tables that store collection and field definitions.
|
|
93
94
|
* This enables dynamic schema management where D1 is the source of truth.
|
|
94
95
|
*/
|
|
95
|
-
async function up$
|
|
96
|
+
async function up$32(db) {
|
|
96
97
|
await db.schema.createTable("_emdash_collections").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("label_singular", "text").addColumn("description", "text").addColumn("icon", "text").addColumn("supports", "text").addColumn("source", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
97
98
|
await db.schema.createTable("_emdash_fields").addColumn("id", "text", (col) => col.primaryKey()).addColumn("collection_id", "text", (col) => col.notNull()).addColumn("slug", "text", (col) => col.notNull()).addColumn("label", "text", (col) => col.notNull()).addColumn("type", "text", (col) => col.notNull()).addColumn("column_type", "text", (col) => col.notNull()).addColumn("required", "integer", (col) => col.defaultTo(0)).addColumn("unique", "integer", (col) => col.defaultTo(0)).addColumn("default_value", "text").addColumn("validation", "text").addColumn("widget", "text").addColumn("options", "text").addColumn("sort_order", "integer", (col) => col.defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addForeignKeyConstraint("fields_collection_fk", ["collection_id"], "_emdash_collections", ["id"], (cb) => cb.onDelete("cascade")).execute();
|
|
98
99
|
await db.schema.createIndex("idx_fields_collection_slug").on("_emdash_fields").columns(["collection_id", "slug"]).unique().execute();
|
|
99
100
|
await db.schema.createIndex("idx_fields_collection").on("_emdash_fields").column("collection_id").execute();
|
|
100
101
|
await db.schema.createIndex("idx_fields_sort").on("_emdash_fields").columns(["collection_id", "sort_order"]).execute();
|
|
101
102
|
}
|
|
102
|
-
async function down$
|
|
103
|
+
async function down$32(db) {
|
|
103
104
|
await db.schema.dropTable("_emdash_fields").execute();
|
|
104
105
|
await db.schema.dropTable("_emdash_collections").execute();
|
|
105
106
|
}
|
|
@@ -107,8 +108,8 @@ async function down$31(db) {
|
|
|
107
108
|
//#endregion
|
|
108
109
|
//#region src/database/migrations/004_plugins.ts
|
|
109
110
|
var _004_plugins_exports = /* @__PURE__ */ __exportAll({
|
|
110
|
-
down: () => down$
|
|
111
|
-
up: () => up$
|
|
111
|
+
down: () => down$31,
|
|
112
|
+
up: () => up$31
|
|
112
113
|
});
|
|
113
114
|
/**
|
|
114
115
|
* Migration: Plugin System Tables
|
|
@@ -118,7 +119,7 @@ var _004_plugins_exports = /* @__PURE__ */ __exportAll({
|
|
|
118
119
|
*
|
|
119
120
|
* @see PLUGIN-SYSTEM.md § Plugin Storage
|
|
120
121
|
*/
|
|
121
|
-
async function up$
|
|
122
|
+
async function up$31(db) {
|
|
122
123
|
await db.schema.createTable("_plugin_storage").addColumn("plugin_id", "text", (col) => col.notNull()).addColumn("collection", "text", (col) => col.notNull()).addColumn("id", "text", (col) => col.notNull()).addColumn("data", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addPrimaryKeyConstraint("pk_plugin_storage", [
|
|
123
124
|
"plugin_id",
|
|
124
125
|
"collection",
|
|
@@ -136,7 +137,7 @@ async function up$30(db) {
|
|
|
136
137
|
"index_name"
|
|
137
138
|
]).execute();
|
|
138
139
|
}
|
|
139
|
-
async function down$
|
|
140
|
+
async function down$31(db) {
|
|
140
141
|
await db.schema.dropTable("_plugin_indexes").execute();
|
|
141
142
|
await db.schema.dropTable("_plugin_state").execute();
|
|
142
143
|
await db.schema.dropTable("_plugin_storage").execute();
|
|
@@ -145,8 +146,8 @@ async function down$30(db) {
|
|
|
145
146
|
//#endregion
|
|
146
147
|
//#region src/database/migrations/005_menus.ts
|
|
147
148
|
var _005_menus_exports = /* @__PURE__ */ __exportAll({
|
|
148
|
-
down: () => down$
|
|
149
|
-
up: () => up$
|
|
149
|
+
down: () => down$30,
|
|
150
|
+
up: () => up$30
|
|
150
151
|
});
|
|
151
152
|
/**
|
|
152
153
|
* Navigation Menus migration
|
|
@@ -154,13 +155,13 @@ var _005_menus_exports = /* @__PURE__ */ __exportAll({
|
|
|
154
155
|
* Creates tables for admin-editable navigation menus.
|
|
155
156
|
* Menu items can reference content entries, taxonomy terms, or custom URLs.
|
|
156
157
|
*/
|
|
157
|
-
async function up$
|
|
158
|
+
async function up$30(db) {
|
|
158
159
|
await db.schema.createTable("_emdash_menus").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
159
160
|
await db.schema.createTable("_emdash_menu_items").addColumn("id", "text", (col) => col.primaryKey()).addColumn("menu_id", "text", (col) => col.notNull()).addColumn("parent_id", "text").addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("type", "text", (col) => col.notNull()).addColumn("reference_collection", "text").addColumn("reference_id", "text").addColumn("custom_url", "text").addColumn("label", "text", (col) => col.notNull()).addColumn("title_attr", "text").addColumn("target", "text").addColumn("css_classes", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addForeignKeyConstraint("menu_items_menu_fk", ["menu_id"], "_emdash_menus", ["id"], (cb) => cb.onDelete("cascade")).addForeignKeyConstraint("menu_items_parent_fk", ["parent_id"], "_emdash_menu_items", ["id"], (cb) => cb.onDelete("cascade")).execute();
|
|
160
161
|
await db.schema.createIndex("idx_menu_items_menu").on("_emdash_menu_items").columns(["menu_id", "sort_order"]).execute();
|
|
161
162
|
await db.schema.createIndex("idx_menu_items_parent").on("_emdash_menu_items").column("parent_id").execute();
|
|
162
163
|
}
|
|
163
|
-
async function down$
|
|
164
|
+
async function down$30(db) {
|
|
164
165
|
await db.schema.dropTable("_emdash_menu_items").execute();
|
|
165
166
|
await db.schema.dropTable("_emdash_menus").execute();
|
|
166
167
|
}
|
|
@@ -168,8 +169,8 @@ async function down$29(db) {
|
|
|
168
169
|
//#endregion
|
|
169
170
|
//#region src/database/migrations/006_taxonomy_defs.ts
|
|
170
171
|
var _006_taxonomy_defs_exports = /* @__PURE__ */ __exportAll({
|
|
171
|
-
down: () => down$
|
|
172
|
-
up: () => up$
|
|
172
|
+
down: () => down$29,
|
|
173
|
+
up: () => up$29
|
|
173
174
|
});
|
|
174
175
|
/**
|
|
175
176
|
* Taxonomy definitions migration
|
|
@@ -177,7 +178,7 @@ var _006_taxonomy_defs_exports = /* @__PURE__ */ __exportAll({
|
|
|
177
178
|
* Adds _emdash_taxonomy_defs table to store taxonomy definitions (category, tag, custom)
|
|
178
179
|
* and seeds default category and tag taxonomies.
|
|
179
180
|
*/
|
|
180
|
-
async function up$
|
|
181
|
+
async function up$29(db) {
|
|
181
182
|
await db.schema.createTable("_emdash_taxonomy_defs").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("label_singular", "text").addColumn("hierarchical", "integer", (col) => col.defaultTo(0)).addColumn("collections", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
182
183
|
await db.insertInto("_emdash_taxonomy_defs").values([{
|
|
183
184
|
id: "taxdef_category",
|
|
@@ -195,22 +196,22 @@ async function up$28(db) {
|
|
|
195
196
|
collections: JSON.stringify(["posts"])
|
|
196
197
|
}]).execute();
|
|
197
198
|
}
|
|
198
|
-
async function down$
|
|
199
|
+
async function down$29(db) {
|
|
199
200
|
await db.schema.dropTable("_emdash_taxonomy_defs").execute();
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
//#endregion
|
|
203
204
|
//#region src/database/migrations/007_widgets.ts
|
|
204
205
|
var _007_widgets_exports = /* @__PURE__ */ __exportAll({
|
|
205
|
-
down: () => down$
|
|
206
|
-
up: () => up$
|
|
206
|
+
down: () => down$28,
|
|
207
|
+
up: () => up$28
|
|
207
208
|
});
|
|
208
|
-
async function up$
|
|
209
|
+
async function up$28(db) {
|
|
209
210
|
await db.schema.createTable("_emdash_widget_areas").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
|
|
210
211
|
await db.schema.createTable("_emdash_widgets").addColumn("id", "text", (col) => col.primaryKey()).addColumn("area_id", "text", (col) => col.notNull().references("_emdash_widget_areas.id").onDelete("cascade")).addColumn("sort_order", "integer", (col) => col.notNull().defaultTo(0)).addColumn("type", "text", (col) => col.notNull()).addColumn("title", "text").addColumn("content", "text").addColumn("menu_name", "text").addColumn("component_id", "text").addColumn("component_props", "text").addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
|
|
211
212
|
await db.schema.createIndex("idx_widgets_area").on("_emdash_widgets").columns(["area_id", "sort_order"]).execute();
|
|
212
213
|
}
|
|
213
|
-
async function down$
|
|
214
|
+
async function down$28(db) {
|
|
214
215
|
await db.schema.dropTable("_emdash_widgets").execute();
|
|
215
216
|
await db.schema.dropTable("_emdash_widget_areas").execute();
|
|
216
217
|
}
|
|
@@ -218,8 +219,8 @@ async function down$27(db) {
|
|
|
218
219
|
//#endregion
|
|
219
220
|
//#region src/database/migrations/008_auth.ts
|
|
220
221
|
var _008_auth_exports = /* @__PURE__ */ __exportAll({
|
|
221
|
-
down: () => down$
|
|
222
|
-
up: () => up$
|
|
222
|
+
down: () => down$27,
|
|
223
|
+
up: () => up$27
|
|
223
224
|
});
|
|
224
225
|
/**
|
|
225
226
|
* Auth migration - passkey-first authentication
|
|
@@ -233,7 +234,7 @@ var _008_auth_exports = /* @__PURE__ */ __exportAll({
|
|
|
233
234
|
* - Creates oauth_accounts table (external provider links)
|
|
234
235
|
* - Creates allowed_domains table (self-signup)
|
|
235
236
|
*/
|
|
236
|
-
async function up$
|
|
237
|
+
async function up$27(db) {
|
|
237
238
|
await db.schema.createTable("users_new").addColumn("id", "text", (col) => col.primaryKey()).addColumn("email", "text", (col) => col.notNull().unique()).addColumn("name", "text").addColumn("avatar_url", "text").addColumn("role", "integer", (col) => col.notNull().defaultTo(10)).addColumn("email_verified", "integer", (col) => col.notNull().defaultTo(0)).addColumn("data", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
238
239
|
await sql`
|
|
239
240
|
INSERT INTO users_new (id, email, name, role, data, created_at, updated_at)
|
|
@@ -266,7 +267,7 @@ async function up$26(db) {
|
|
|
266
267
|
await db.schema.createTable("auth_challenges").addColumn("challenge", "text", (col) => col.primaryKey()).addColumn("type", "text", (col) => col.notNull()).addColumn("user_id", "text").addColumn("data", "text").addColumn("expires_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
267
268
|
await db.schema.createIndex("idx_auth_challenges_expires").on("auth_challenges").column("expires_at").execute();
|
|
268
269
|
}
|
|
269
|
-
async function down$
|
|
270
|
+
async function down$27(db) {
|
|
270
271
|
await db.schema.dropTable("auth_challenges").execute();
|
|
271
272
|
await db.schema.dropTable("allowed_domains").execute();
|
|
272
273
|
await db.schema.dropTable("oauth_accounts").execute();
|
|
@@ -299,8 +300,8 @@ async function down$26(db) {
|
|
|
299
300
|
//#endregion
|
|
300
301
|
//#region src/database/migrations/009_user_disabled.ts
|
|
301
302
|
var _009_user_disabled_exports = /* @__PURE__ */ __exportAll({
|
|
302
|
-
down: () => down$
|
|
303
|
-
up: () => up$
|
|
303
|
+
down: () => down$26,
|
|
304
|
+
up: () => up$26
|
|
304
305
|
});
|
|
305
306
|
/**
|
|
306
307
|
* User disabled column - for soft-disabling users
|
|
@@ -309,19 +310,19 @@ var _009_user_disabled_exports = /* @__PURE__ */ __exportAll({
|
|
|
309
310
|
* - Adds disabled column to users table (INTEGER, default 0)
|
|
310
311
|
* - Disabled users cannot log in
|
|
311
312
|
*/
|
|
312
|
-
async function up$
|
|
313
|
+
async function up$26(db) {
|
|
313
314
|
await sql`ALTER TABLE users ADD COLUMN disabled INTEGER NOT NULL DEFAULT 0`.execute(db);
|
|
314
315
|
await db.schema.createIndex("idx_users_disabled").on("users").column("disabled").execute();
|
|
315
316
|
}
|
|
316
|
-
async function down$
|
|
317
|
+
async function down$26(db) {
|
|
317
318
|
await db.schema.dropIndex("idx_users_disabled").execute();
|
|
318
319
|
}
|
|
319
320
|
|
|
320
321
|
//#endregion
|
|
321
322
|
//#region src/database/migrations/011_sections.ts
|
|
322
323
|
var _011_sections_exports = /* @__PURE__ */ __exportAll({
|
|
323
|
-
down: () => down$
|
|
324
|
-
up: () => up$
|
|
324
|
+
down: () => down$25,
|
|
325
|
+
up: () => up$25
|
|
325
326
|
});
|
|
326
327
|
/**
|
|
327
328
|
* Migration: Add sections tables and performance indexes
|
|
@@ -330,13 +331,13 @@ var _011_sections_exports = /* @__PURE__ */ __exportAll({
|
|
|
330
331
|
* They provide a library of pre-built page sections (heroes, CTAs, testimonials, etc.)
|
|
331
332
|
* that content authors can browse and insert with a single click.
|
|
332
333
|
*/
|
|
333
|
-
async function up$
|
|
334
|
+
async function up$25(db) {
|
|
334
335
|
await db.schema.createTable("_emdash_section_categories").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("sort_order", "integer", (col) => col.defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
|
|
335
336
|
await db.schema.createTable("_emdash_sections").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("title", "text", (col) => col.notNull()).addColumn("description", "text").addColumn("category_id", "text", (col) => col.references("_emdash_section_categories.id").onDelete("set null")).addColumn("keywords", "text").addColumn("content", "text", (col) => col.notNull()).addColumn("preview_media_id", "text").addColumn("source", "text", (col) => col.notNull().defaultTo("user")).addColumn("theme_id", "text").addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).addColumn("updated_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
|
|
336
337
|
await db.schema.createIndex("idx_sections_category").on("_emdash_sections").columns(["category_id"]).execute();
|
|
337
338
|
await db.schema.createIndex("idx_sections_source").on("_emdash_sections").columns(["source"]).execute();
|
|
338
339
|
}
|
|
339
|
-
async function down$
|
|
340
|
+
async function down$25(db) {
|
|
340
341
|
await db.schema.dropIndex("idx_sections_source").execute();
|
|
341
342
|
await db.schema.dropIndex("idx_sections_category").execute();
|
|
342
343
|
await db.schema.dropTable("_emdash_sections").execute();
|
|
@@ -346,8 +347,8 @@ async function down$24(db) {
|
|
|
346
347
|
//#endregion
|
|
347
348
|
//#region src/database/migrations/012_search.ts
|
|
348
349
|
var _012_search_exports = /* @__PURE__ */ __exportAll({
|
|
349
|
-
down: () => down$
|
|
350
|
-
up: () => up$
|
|
350
|
+
down: () => down$24,
|
|
351
|
+
up: () => up$24
|
|
351
352
|
});
|
|
352
353
|
/**
|
|
353
354
|
* Migration: Search Support
|
|
@@ -355,11 +356,11 @@ var _012_search_exports = /* @__PURE__ */ __exportAll({
|
|
|
355
356
|
* Adds search configuration to collections and searchable flag to fields.
|
|
356
357
|
* FTS5 tables are created dynamically when search is enabled for a collection.
|
|
357
358
|
*/
|
|
358
|
-
async function up$
|
|
359
|
+
async function up$24(db) {
|
|
359
360
|
await db.schema.alterTable("_emdash_collections").addColumn("search_config", "text").execute();
|
|
360
361
|
await db.schema.alterTable("_emdash_fields").addColumn("searchable", "integer", (col) => col.defaultTo(0)).execute();
|
|
361
362
|
}
|
|
362
|
-
async function down$
|
|
363
|
+
async function down$24(db) {
|
|
363
364
|
await db.schema.alterTable("_emdash_fields").dropColumn("searchable").execute();
|
|
364
365
|
await db.schema.alterTable("_emdash_collections").dropColumn("search_config").execute();
|
|
365
366
|
}
|
|
@@ -367,8 +368,8 @@ async function down$23(db) {
|
|
|
367
368
|
//#endregion
|
|
368
369
|
//#region src/database/migrations/013_scheduled_publishing.ts
|
|
369
370
|
var _013_scheduled_publishing_exports = /* @__PURE__ */ __exportAll({
|
|
370
|
-
down: () => down$
|
|
371
|
-
up: () => up$
|
|
371
|
+
down: () => down$23,
|
|
372
|
+
up: () => up$23
|
|
372
373
|
});
|
|
373
374
|
/**
|
|
374
375
|
* Migration: Add scheduled publishing support
|
|
@@ -377,7 +378,7 @@ var _013_scheduled_publishing_exports = /* @__PURE__ */ __exportAll({
|
|
|
377
378
|
* When scheduled_at is set and status is 'scheduled', the content
|
|
378
379
|
* will be auto-published when the scheduled time is reached.
|
|
379
380
|
*/
|
|
380
|
-
async function up$
|
|
381
|
+
async function up$23(db) {
|
|
381
382
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
382
383
|
for (const tableName of tableNames) {
|
|
383
384
|
const table = { name: tableName };
|
|
@@ -392,7 +393,7 @@ async function up$22(db) {
|
|
|
392
393
|
`.execute(db);
|
|
393
394
|
}
|
|
394
395
|
}
|
|
395
|
-
async function down$
|
|
396
|
+
async function down$23(db) {
|
|
396
397
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
397
398
|
for (const tableName of tableNames) {
|
|
398
399
|
const table = { name: tableName };
|
|
@@ -409,10 +410,10 @@ async function down$22(db) {
|
|
|
409
410
|
//#endregion
|
|
410
411
|
//#region src/database/migrations/014_draft_revisions.ts
|
|
411
412
|
var _014_draft_revisions_exports = /* @__PURE__ */ __exportAll({
|
|
412
|
-
down: () => down$
|
|
413
|
-
up: () => up$
|
|
413
|
+
down: () => down$22,
|
|
414
|
+
up: () => up$22
|
|
414
415
|
});
|
|
415
|
-
async function up$
|
|
416
|
+
async function up$22(db) {
|
|
416
417
|
const tables = await db.selectFrom("_emdash_collections").select("slug").execute();
|
|
417
418
|
for (const row of tables) {
|
|
418
419
|
const tableName = `ec_${row.slug}`;
|
|
@@ -434,7 +435,7 @@ async function up$21(db) {
|
|
|
434
435
|
`.execute(db);
|
|
435
436
|
}
|
|
436
437
|
}
|
|
437
|
-
async function down$
|
|
438
|
+
async function down$22(db) {
|
|
438
439
|
const tables = await db.selectFrom("_emdash_collections").select("slug").execute();
|
|
439
440
|
for (const row of tables) {
|
|
440
441
|
const tableName = `ec_${row.slug}`;
|
|
@@ -458,8 +459,8 @@ async function down$21(db) {
|
|
|
458
459
|
//#endregion
|
|
459
460
|
//#region src/database/migrations/015_indexes.ts
|
|
460
461
|
var _015_indexes_exports = /* @__PURE__ */ __exportAll({
|
|
461
|
-
down: () => down$
|
|
462
|
-
up: () => up$
|
|
462
|
+
down: () => down$21,
|
|
463
|
+
up: () => up$21
|
|
463
464
|
});
|
|
464
465
|
/**
|
|
465
466
|
* Add performance indexes for common query patterns.
|
|
@@ -472,7 +473,7 @@ var _015_indexes_exports = /* @__PURE__ */ __exportAll({
|
|
|
472
473
|
* 5. Retroactive author_id + updated_at on existing ec_* content tables
|
|
473
474
|
* (new tables get these from createContentTable() in registry.ts)
|
|
474
475
|
*/
|
|
475
|
-
async function up$
|
|
476
|
+
async function up$21(db) {
|
|
476
477
|
await db.schema.createIndex("idx_media_mime_type").on("media").column("mime_type").execute();
|
|
477
478
|
await db.schema.createIndex("idx_media_filename").on("media").column("filename").execute();
|
|
478
479
|
await db.schema.createIndex("idx_media_created_at").on("media").column("created_at").execute();
|
|
@@ -492,7 +493,7 @@ async function up$20(db) {
|
|
|
492
493
|
`.execute(db);
|
|
493
494
|
}
|
|
494
495
|
}
|
|
495
|
-
async function down$
|
|
496
|
+
async function down$21(db) {
|
|
496
497
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
497
498
|
for (const tableName of tableNames) {
|
|
498
499
|
const table = { name: tableName };
|
|
@@ -510,8 +511,8 @@ async function down$20(db) {
|
|
|
510
511
|
//#endregion
|
|
511
512
|
//#region src/database/migrations/016_api_tokens.ts
|
|
512
513
|
var _016_api_tokens_exports = /* @__PURE__ */ __exportAll({
|
|
513
|
-
down: () => down$
|
|
514
|
-
up: () => up$
|
|
514
|
+
down: () => down$20,
|
|
515
|
+
up: () => up$20
|
|
515
516
|
});
|
|
516
517
|
/**
|
|
517
518
|
* API token tables for programmatic access.
|
|
@@ -521,7 +522,7 @@ var _016_api_tokens_exports = /* @__PURE__ */ __exportAll({
|
|
|
521
522
|
* 2. _emdash_oauth_tokens — OAuth access/refresh tokens (ec_oat_/ec_ort_...)
|
|
522
523
|
* 3. _emdash_device_codes — OAuth Device Flow state (RFC 8628)
|
|
523
524
|
*/
|
|
524
|
-
async function up$
|
|
525
|
+
async function up$20(db) {
|
|
525
526
|
await db.schema.createTable("_emdash_api_tokens").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("token_hash", "text", (col) => col.notNull().unique()).addColumn("prefix", "text", (col) => col.notNull()).addColumn("user_id", "text", (col) => col.notNull()).addColumn("scopes", "text", (col) => col.notNull()).addColumn("expires_at", "text").addColumn("last_used_at", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addForeignKeyConstraint("api_tokens_user_fk", ["user_id"], "users", ["id"], (cb) => cb.onDelete("cascade")).execute();
|
|
526
527
|
await db.schema.createIndex("idx_api_tokens_token_hash").on("_emdash_api_tokens").column("token_hash").execute();
|
|
527
528
|
await db.schema.createIndex("idx_api_tokens_user_id").on("_emdash_api_tokens").column("user_id").execute();
|
|
@@ -530,7 +531,7 @@ async function up$19(db) {
|
|
|
530
531
|
await db.schema.createIndex("idx_oauth_tokens_expires").on("_emdash_oauth_tokens").column("expires_at").execute();
|
|
531
532
|
await db.schema.createTable("_emdash_device_codes").addColumn("device_code", "text", (col) => col.primaryKey()).addColumn("user_code", "text", (col) => col.notNull().unique()).addColumn("scopes", "text", (col) => col.notNull()).addColumn("user_id", "text").addColumn("status", "text", (col) => col.notNull().defaultTo("pending")).addColumn("expires_at", "text", (col) => col.notNull()).addColumn("interval", "integer", (col) => col.notNull().defaultTo(5)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
532
533
|
}
|
|
533
|
-
async function down$
|
|
534
|
+
async function down$20(db) {
|
|
534
535
|
await db.schema.dropTable("_emdash_device_codes").execute();
|
|
535
536
|
await db.schema.dropTable("_emdash_oauth_tokens").execute();
|
|
536
537
|
await db.schema.dropTable("_emdash_api_tokens").execute();
|
|
@@ -539,8 +540,8 @@ async function down$19(db) {
|
|
|
539
540
|
//#endregion
|
|
540
541
|
//#region src/database/migrations/017_authorization_codes.ts
|
|
541
542
|
var _017_authorization_codes_exports = /* @__PURE__ */ __exportAll({
|
|
542
|
-
down: () => down$
|
|
543
|
-
up: () => up$
|
|
543
|
+
down: () => down$19,
|
|
544
|
+
up: () => up$19
|
|
544
545
|
});
|
|
545
546
|
/**
|
|
546
547
|
* Authorization codes for OAuth 2.1 Authorization Code + PKCE flow.
|
|
@@ -550,20 +551,20 @@ var _017_authorization_codes_exports = /* @__PURE__ */ __exportAll({
|
|
|
550
551
|
*
|
|
551
552
|
* Also adds client_id tracking to oauth_tokens for per-client revocation.
|
|
552
553
|
*/
|
|
553
|
-
async function up$
|
|
554
|
+
async function up$19(db) {
|
|
554
555
|
await db.schema.createTable("_emdash_authorization_codes").addColumn("code_hash", "text", (col) => col.primaryKey()).addColumn("client_id", "text", (col) => col.notNull()).addColumn("redirect_uri", "text", (col) => col.notNull()).addColumn("user_id", "text", (col) => col.notNull()).addColumn("scopes", "text", (col) => col.notNull()).addColumn("code_challenge", "text", (col) => col.notNull()).addColumn("code_challenge_method", "text", (col) => col.notNull().defaultTo("S256")).addColumn("resource", "text").addColumn("expires_at", "text", (col) => col.notNull()).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addForeignKeyConstraint("auth_codes_user_fk", ["user_id"], "users", ["id"], (cb) => cb.onDelete("cascade")).execute();
|
|
555
556
|
await db.schema.createIndex("idx_auth_codes_expires").on("_emdash_authorization_codes").column("expires_at").execute();
|
|
556
557
|
await sql`ALTER TABLE _emdash_oauth_tokens ADD COLUMN client_id TEXT`.execute(db);
|
|
557
558
|
}
|
|
558
|
-
async function down$
|
|
559
|
+
async function down$19(db) {
|
|
559
560
|
await db.schema.dropTable("_emdash_authorization_codes").execute();
|
|
560
561
|
}
|
|
561
562
|
|
|
562
563
|
//#endregion
|
|
563
564
|
//#region src/database/migrations/018_seo.ts
|
|
564
565
|
var _018_seo_exports = /* @__PURE__ */ __exportAll({
|
|
565
|
-
down: () => down$
|
|
566
|
-
up: () => up$
|
|
566
|
+
down: () => down$18,
|
|
567
|
+
up: () => up$18
|
|
567
568
|
});
|
|
568
569
|
/**
|
|
569
570
|
* Migration: SEO support
|
|
@@ -576,7 +577,7 @@ var _018_seo_exports = /* @__PURE__ */ __exportAll({
|
|
|
576
577
|
* need it. The `has_seo` flag controls whether the admin shows SEO fields
|
|
577
578
|
* and whether the collection's content appears in sitemaps.
|
|
578
579
|
*/
|
|
579
|
-
async function up$
|
|
580
|
+
async function up$18(db) {
|
|
580
581
|
await db.schema.createTable("_emdash_seo").addColumn("collection", "text", (col) => col.notNull()).addColumn("content_id", "text", (col) => col.notNull()).addColumn("seo_title", "text").addColumn("seo_description", "text").addColumn("seo_image", "text").addColumn("seo_canonical", "text").addColumn("seo_no_index", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.notNull().defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.notNull().defaultTo(currentTimestamp(db))).addPrimaryKeyConstraint("_emdash_seo_pk", ["collection", "content_id"]).execute();
|
|
581
582
|
await sql`
|
|
582
583
|
CREATE INDEX idx_emdash_seo_collection
|
|
@@ -587,7 +588,7 @@ async function up$17(db) {
|
|
|
587
588
|
ADD COLUMN has_seo INTEGER NOT NULL DEFAULT 0
|
|
588
589
|
`.execute(db);
|
|
589
590
|
}
|
|
590
|
-
async function down$
|
|
591
|
+
async function down$18(db) {
|
|
591
592
|
await sql`DROP TABLE IF EXISTS _emdash_seo`.execute(db);
|
|
592
593
|
await sql`
|
|
593
594
|
ALTER TABLE _emdash_collections
|
|
@@ -598,8 +599,8 @@ async function down$17(db) {
|
|
|
598
599
|
//#endregion
|
|
599
600
|
//#region src/database/migrations/019_i18n.ts
|
|
600
601
|
var _019_i18n_exports = /* @__PURE__ */ __exportAll({
|
|
601
|
-
down: () => down$
|
|
602
|
-
up: () => up$
|
|
602
|
+
down: () => down$17,
|
|
603
|
+
up: () => up$17
|
|
603
604
|
});
|
|
604
605
|
/**
|
|
605
606
|
* Quote an identifier for use in raw SQL. Escapes embedded double-quotes
|
|
@@ -712,7 +713,7 @@ async function upPostgres(db) {
|
|
|
712
713
|
ADD COLUMN translatable INTEGER NOT NULL DEFAULT 1
|
|
713
714
|
`.execute(db);
|
|
714
715
|
}
|
|
715
|
-
async function up$
|
|
716
|
+
async function up$17(db) {
|
|
716
717
|
if (!isSqlite(db)) return upPostgres(db);
|
|
717
718
|
const orphanedTmps = await listTablesLike(db, "ec_%_i18n_tmp");
|
|
718
719
|
for (const tmpName of orphanedTmps) {
|
|
@@ -829,7 +830,7 @@ async function downPostgres(db) {
|
|
|
829
830
|
await sql`ALTER TABLE ${sql.ref(t)} DROP COLUMN translation_group`.execute(db);
|
|
830
831
|
}
|
|
831
832
|
}
|
|
832
|
-
async function down$
|
|
833
|
+
async function down$17(db) {
|
|
833
834
|
if (!isSqlite(db)) return downPostgres(db);
|
|
834
835
|
await sql`
|
|
835
836
|
ALTER TABLE _emdash_fields
|
|
@@ -936,8 +937,8 @@ async function down$16(db) {
|
|
|
936
937
|
//#endregion
|
|
937
938
|
//#region src/database/migrations/020_collection_url_pattern.ts
|
|
938
939
|
var _020_collection_url_pattern_exports = /* @__PURE__ */ __exportAll({
|
|
939
|
-
down: () => down$
|
|
940
|
-
up: () => up$
|
|
940
|
+
down: () => down$16,
|
|
941
|
+
up: () => up$16
|
|
941
942
|
});
|
|
942
943
|
/**
|
|
943
944
|
* Migration: URL pattern for collections
|
|
@@ -946,13 +947,13 @@ var _020_collection_url_pattern_exports = /* @__PURE__ */ __exportAll({
|
|
|
946
947
|
* can declare its own URL structure (e.g. "/{slug}" for pages, "/blog/{slug}"
|
|
947
948
|
* for posts). Used for menu URL resolution, sitemaps, and path-based lookups.
|
|
948
949
|
*/
|
|
949
|
-
async function up$
|
|
950
|
+
async function up$16(db) {
|
|
950
951
|
await sql`
|
|
951
952
|
ALTER TABLE _emdash_collections
|
|
952
953
|
ADD COLUMN url_pattern TEXT
|
|
953
954
|
`.execute(db);
|
|
954
955
|
}
|
|
955
|
-
async function down$
|
|
956
|
+
async function down$16(db) {
|
|
956
957
|
await sql`
|
|
957
958
|
ALTER TABLE _emdash_collections
|
|
958
959
|
DROP COLUMN url_pattern
|
|
@@ -962,8 +963,8 @@ async function down$15(db) {
|
|
|
962
963
|
//#endregion
|
|
963
964
|
//#region src/database/migrations/021_remove_section_categories.ts
|
|
964
965
|
var _021_remove_section_categories_exports = /* @__PURE__ */ __exportAll({
|
|
965
|
-
down: () => down$
|
|
966
|
-
up: () => up$
|
|
966
|
+
down: () => down$15,
|
|
967
|
+
up: () => up$15
|
|
967
968
|
});
|
|
968
969
|
/**
|
|
969
970
|
* Migration: Remove section categories
|
|
@@ -972,12 +973,12 @@ var _021_remove_section_categories_exports = /* @__PURE__ */ __exportAll({
|
|
|
972
973
|
* Rather than building the missing UI for a feature with very little need at this stage,
|
|
973
974
|
* we're removing the feature entirely.
|
|
974
975
|
*/
|
|
975
|
-
async function up$
|
|
976
|
+
async function up$15(db) {
|
|
976
977
|
await db.schema.dropIndex("idx_sections_category").ifExists().execute();
|
|
977
978
|
await db.schema.alterTable("_emdash_sections").dropColumn("category_id").execute();
|
|
978
979
|
await db.schema.dropTable("_emdash_section_categories").execute();
|
|
979
980
|
}
|
|
980
|
-
async function down$
|
|
981
|
+
async function down$15(db) {
|
|
981
982
|
await db.schema.createTable("_emdash_section_categories").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("label", "text", (col) => col.notNull()).addColumn("sort_order", "integer", (col) => col.defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(sql`CURRENT_TIMESTAMP`)).execute();
|
|
982
983
|
await db.schema.alterTable("_emdash_sections").addColumn("category_id", "text", (col) => col.references("_emdash_section_categories.id").onDelete("set null")).execute();
|
|
983
984
|
await db.schema.createIndex("idx_sections_category").on("_emdash_sections").columns(["category_id"]).execute();
|
|
@@ -986,8 +987,8 @@ async function down$14(db) {
|
|
|
986
987
|
//#endregion
|
|
987
988
|
//#region src/database/migrations/022_marketplace_plugin_state.ts
|
|
988
989
|
var _022_marketplace_plugin_state_exports = /* @__PURE__ */ __exportAll({
|
|
989
|
-
down: () => down$
|
|
990
|
-
up: () => up$
|
|
990
|
+
down: () => down$14,
|
|
991
|
+
up: () => up$14
|
|
991
992
|
});
|
|
992
993
|
/**
|
|
993
994
|
* Migration: Add marketplace fields to _plugin_state
|
|
@@ -996,7 +997,7 @@ var _022_marketplace_plugin_state_exports = /* @__PURE__ */ __exportAll({
|
|
|
996
997
|
* whether a plugin was installed from config or marketplace,
|
|
997
998
|
* and which marketplace version is installed.
|
|
998
999
|
*/
|
|
999
|
-
async function up$
|
|
1000
|
+
async function up$14(db) {
|
|
1000
1001
|
await sql`
|
|
1001
1002
|
ALTER TABLE _plugin_state
|
|
1002
1003
|
ADD COLUMN source TEXT NOT NULL DEFAULT 'config'
|
|
@@ -1011,7 +1012,7 @@ async function up$13(db) {
|
|
|
1011
1012
|
WHERE source = 'marketplace'
|
|
1012
1013
|
`.execute(db);
|
|
1013
1014
|
}
|
|
1014
|
-
async function down$
|
|
1015
|
+
async function down$14(db) {
|
|
1015
1016
|
await sql`
|
|
1016
1017
|
DROP INDEX IF EXISTS idx_plugin_state_source
|
|
1017
1018
|
`.execute(db);
|
|
@@ -1028,8 +1029,8 @@ async function down$13(db) {
|
|
|
1028
1029
|
//#endregion
|
|
1029
1030
|
//#region src/database/migrations/023_plugin_metadata.ts
|
|
1030
1031
|
var _023_plugin_metadata_exports = /* @__PURE__ */ __exportAll({
|
|
1031
|
-
down: () => down$
|
|
1032
|
-
up: () => up$
|
|
1032
|
+
down: () => down$13,
|
|
1033
|
+
up: () => up$13
|
|
1033
1034
|
});
|
|
1034
1035
|
/**
|
|
1035
1036
|
* Migration: Add display metadata to _plugin_state
|
|
@@ -1038,7 +1039,7 @@ var _023_plugin_metadata_exports = /* @__PURE__ */ __exportAll({
|
|
|
1038
1039
|
* so the admin UI can show meaningful info without re-fetching
|
|
1039
1040
|
* from the marketplace on every page load.
|
|
1040
1041
|
*/
|
|
1041
|
-
async function up$
|
|
1042
|
+
async function up$13(db) {
|
|
1042
1043
|
await sql`
|
|
1043
1044
|
ALTER TABLE _plugin_state
|
|
1044
1045
|
ADD COLUMN display_name TEXT
|
|
@@ -1048,7 +1049,7 @@ async function up$12(db) {
|
|
|
1048
1049
|
ADD COLUMN description TEXT
|
|
1049
1050
|
`.execute(db);
|
|
1050
1051
|
}
|
|
1051
|
-
async function down$
|
|
1052
|
+
async function down$13(db) {
|
|
1052
1053
|
await sql`
|
|
1053
1054
|
ALTER TABLE _plugin_state
|
|
1054
1055
|
DROP COLUMN description
|
|
@@ -1062,8 +1063,8 @@ async function down$12(db) {
|
|
|
1062
1063
|
//#endregion
|
|
1063
1064
|
//#region src/database/migrations/024_media_placeholders.ts
|
|
1064
1065
|
var _024_media_placeholders_exports = /* @__PURE__ */ __exportAll({
|
|
1065
|
-
down: () => down$
|
|
1066
|
-
up: () => up$
|
|
1066
|
+
down: () => down$12,
|
|
1067
|
+
up: () => up$12
|
|
1067
1068
|
});
|
|
1068
1069
|
/**
|
|
1069
1070
|
* Migration: Add placeholder columns to media table
|
|
@@ -1071,7 +1072,7 @@ var _024_media_placeholders_exports = /* @__PURE__ */ __exportAll({
|
|
|
1071
1072
|
* Stores blurhash and dominant_color for LQIP (Low Quality Image Placeholder)
|
|
1072
1073
|
* support. Generated at upload time from image pixel data.
|
|
1073
1074
|
*/
|
|
1074
|
-
async function up$
|
|
1075
|
+
async function up$12(db) {
|
|
1075
1076
|
await sql`
|
|
1076
1077
|
ALTER TABLE media
|
|
1077
1078
|
ADD COLUMN blurhash TEXT
|
|
@@ -1081,7 +1082,7 @@ async function up$11(db) {
|
|
|
1081
1082
|
ADD COLUMN dominant_color TEXT
|
|
1082
1083
|
`.execute(db);
|
|
1083
1084
|
}
|
|
1084
|
-
async function down$
|
|
1085
|
+
async function down$12(db) {
|
|
1085
1086
|
await sql`
|
|
1086
1087
|
ALTER TABLE media
|
|
1087
1088
|
DROP COLUMN dominant_color
|
|
@@ -1095,8 +1096,8 @@ async function down$11(db) {
|
|
|
1095
1096
|
//#endregion
|
|
1096
1097
|
//#region src/database/migrations/025_oauth_clients.ts
|
|
1097
1098
|
var _025_oauth_clients_exports = /* @__PURE__ */ __exportAll({
|
|
1098
|
-
down: () => down$
|
|
1099
|
-
up: () => up$
|
|
1099
|
+
down: () => down$11,
|
|
1100
|
+
up: () => up$11
|
|
1100
1101
|
});
|
|
1101
1102
|
/**
|
|
1102
1103
|
* Migration: Create OAuth clients table
|
|
@@ -1107,18 +1108,18 @@ var _025_oauth_clients_exports = /* @__PURE__ */ __exportAll({
|
|
|
1107
1108
|
* Each client has a set of pre-registered redirect URIs (JSON array).
|
|
1108
1109
|
* The authorize endpoint rejects any redirect_uri not in the client's list.
|
|
1109
1110
|
*/
|
|
1110
|
-
async function up$
|
|
1111
|
+
async function up$11(db) {
|
|
1111
1112
|
await db.schema.createTable("_emdash_oauth_clients").addColumn("id", "text", (col) => col.primaryKey()).addColumn("name", "text", (col) => col.notNull()).addColumn("redirect_uris", "text", (col) => col.notNull()).addColumn("scopes", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
1112
1113
|
}
|
|
1113
|
-
async function down$
|
|
1114
|
+
async function down$11(db) {
|
|
1114
1115
|
await db.schema.dropTable("_emdash_oauth_clients").execute();
|
|
1115
1116
|
}
|
|
1116
1117
|
|
|
1117
1118
|
//#endregion
|
|
1118
1119
|
//#region src/database/migrations/026_cron_tasks.ts
|
|
1119
1120
|
var _026_cron_tasks_exports = /* @__PURE__ */ __exportAll({
|
|
1120
|
-
down: () => down$
|
|
1121
|
-
up: () => up$
|
|
1121
|
+
down: () => down$10,
|
|
1122
|
+
up: () => up$10
|
|
1122
1123
|
});
|
|
1123
1124
|
/**
|
|
1124
1125
|
* Migration: Create cron tasks table for plugin scheduled tasks.
|
|
@@ -1129,7 +1130,7 @@ var _026_cron_tasks_exports = /* @__PURE__ */ __exportAll({
|
|
|
1129
1130
|
* The `next_run_at` + `status` + `enabled` index drives the "find overdue
|
|
1130
1131
|
* tasks" query used by CronExecutor.tick().
|
|
1131
1132
|
*/
|
|
1132
|
-
async function up$
|
|
1133
|
+
async function up$10(db) {
|
|
1133
1134
|
await db.schema.createTable("_emdash_cron_tasks").addColumn("id", "text", (col) => col.primaryKey()).addColumn("plugin_id", "text", (col) => col.notNull()).addColumn("task_name", "text", (col) => col.notNull()).addColumn("schedule", "text", (col) => col.notNull()).addColumn("is_oneshot", "integer", (col) => col.notNull().defaultTo(0)).addColumn("data", "text").addColumn("next_run_at", "text", (col) => col.notNull()).addColumn("last_run_at", "text").addColumn("status", "text", (col) => col.notNull().defaultTo("idle")).addColumn("locked_at", "text").addColumn("enabled", "integer", (col) => col.notNull().defaultTo(1)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addUniqueConstraint("uq_cron_tasks_plugin_task", ["plugin_id", "task_name"]).execute();
|
|
1134
1135
|
await db.schema.createIndex("idx_cron_tasks_due").on("_emdash_cron_tasks").columns([
|
|
1135
1136
|
"enabled",
|
|
@@ -1138,17 +1139,17 @@ async function up$9(db) {
|
|
|
1138
1139
|
]).execute();
|
|
1139
1140
|
await db.schema.createIndex("idx_cron_tasks_plugin").on("_emdash_cron_tasks").column("plugin_id").execute();
|
|
1140
1141
|
}
|
|
1141
|
-
async function down$
|
|
1142
|
+
async function down$10(db) {
|
|
1142
1143
|
await db.schema.dropTable("_emdash_cron_tasks").execute();
|
|
1143
1144
|
}
|
|
1144
1145
|
|
|
1145
1146
|
//#endregion
|
|
1146
1147
|
//#region src/database/migrations/027_comments.ts
|
|
1147
1148
|
var _027_comments_exports = /* @__PURE__ */ __exportAll({
|
|
1148
|
-
down: () => down$
|
|
1149
|
-
up: () => up$
|
|
1149
|
+
down: () => down$9,
|
|
1150
|
+
up: () => up$9
|
|
1150
1151
|
});
|
|
1151
|
-
async function up$
|
|
1152
|
+
async function up$9(db) {
|
|
1152
1153
|
await db.schema.createTable("_emdash_comments").addColumn("id", "text", (col) => col.primaryKey()).addColumn("collection", "text", (col) => col.notNull()).addColumn("content_id", "text", (col) => col.notNull()).addColumn("parent_id", "text", (col) => col.references("_emdash_comments.id").onDelete("cascade")).addColumn("author_name", "text", (col) => col.notNull()).addColumn("author_email", "text", (col) => col.notNull()).addColumn("author_url", "text").addColumn("author_user_id", "text", (col) => col.references("users.id").onDelete("set null")).addColumn("body", "text", (col) => col.notNull()).addColumn("status", "text", (col) => col.notNull().defaultTo("pending")).addColumn("ip_hash", "text").addColumn("user_agent", "text").addColumn("moderation_metadata", "text").addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
1153
1154
|
await db.schema.createIndex("idx_comments_content").on("_emdash_comments").columns([
|
|
1154
1155
|
"collection",
|
|
@@ -1164,30 +1165,30 @@ async function up$8(db) {
|
|
|
1164
1165
|
await db.schema.alterTable("_emdash_collections").addColumn("comments_closed_after_days", "integer", (col) => col.defaultTo(90)).execute();
|
|
1165
1166
|
await db.schema.alterTable("_emdash_collections").addColumn("comments_auto_approve_users", "integer", (col) => col.defaultTo(1)).execute();
|
|
1166
1167
|
}
|
|
1167
|
-
async function down$
|
|
1168
|
+
async function down$9(db) {
|
|
1168
1169
|
await db.schema.dropTable("_emdash_comments").execute();
|
|
1169
1170
|
}
|
|
1170
1171
|
|
|
1171
1172
|
//#endregion
|
|
1172
1173
|
//#region src/database/migrations/028_drop_author_url.ts
|
|
1173
1174
|
var _028_drop_author_url_exports = /* @__PURE__ */ __exportAll({
|
|
1174
|
-
down: () => down$
|
|
1175
|
-
up: () => up$
|
|
1175
|
+
down: () => down$8,
|
|
1176
|
+
up: () => up$8
|
|
1176
1177
|
});
|
|
1177
|
-
async function up$
|
|
1178
|
+
async function up$8(db) {
|
|
1178
1179
|
await sql`ALTER TABLE _emdash_comments DROP COLUMN author_url`.execute(db);
|
|
1179
1180
|
}
|
|
1180
|
-
async function down$
|
|
1181
|
+
async function down$8(db) {
|
|
1181
1182
|
await db.schema.alterTable("_emdash_comments").addColumn("author_url", "text").execute();
|
|
1182
1183
|
}
|
|
1183
1184
|
|
|
1184
1185
|
//#endregion
|
|
1185
1186
|
//#region src/database/migrations/029_redirects.ts
|
|
1186
1187
|
var _029_redirects_exports = /* @__PURE__ */ __exportAll({
|
|
1187
|
-
down: () => down$
|
|
1188
|
-
up: () => up$
|
|
1188
|
+
down: () => down$7,
|
|
1189
|
+
up: () => up$7
|
|
1189
1190
|
});
|
|
1190
|
-
async function up$
|
|
1191
|
+
async function up$7(db) {
|
|
1191
1192
|
await db.schema.createTable("_emdash_redirects").addColumn("id", "text", (col) => col.primaryKey()).addColumn("source", "text", (col) => col.notNull()).addColumn("destination", "text", (col) => col.notNull()).addColumn("type", "integer", (col) => col.notNull().defaultTo(301)).addColumn("is_pattern", "integer", (col) => col.notNull().defaultTo(0)).addColumn("enabled", "integer", (col) => col.notNull().defaultTo(1)).addColumn("hits", "integer", (col) => col.notNull().defaultTo(0)).addColumn("last_hit_at", "text").addColumn("group_name", "text").addColumn("auto", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
1192
1193
|
await db.schema.createIndex("idx_redirects_source").on("_emdash_redirects").column("source").execute();
|
|
1193
1194
|
await db.schema.createIndex("idx_redirects_enabled").on("_emdash_redirects").column("enabled").execute();
|
|
@@ -1196,7 +1197,7 @@ async function up$6(db) {
|
|
|
1196
1197
|
await db.schema.createIndex("idx_404_log_path").on("_emdash_404_log").column("path").execute();
|
|
1197
1198
|
await db.schema.createIndex("idx_404_log_created").on("_emdash_404_log").column("created_at").execute();
|
|
1198
1199
|
}
|
|
1199
|
-
async function down$
|
|
1200
|
+
async function down$7(db) {
|
|
1200
1201
|
await db.schema.dropTable("_emdash_404_log").execute();
|
|
1201
1202
|
await db.schema.dropTable("_emdash_redirects").execute();
|
|
1202
1203
|
}
|
|
@@ -1204,8 +1205,8 @@ async function down$6(db) {
|
|
|
1204
1205
|
//#endregion
|
|
1205
1206
|
//#region src/database/migrations/030_widen_scheduled_index.ts
|
|
1206
1207
|
var _030_widen_scheduled_index_exports = /* @__PURE__ */ __exportAll({
|
|
1207
|
-
down: () => down$
|
|
1208
|
-
up: () => up$
|
|
1208
|
+
down: () => down$6,
|
|
1209
|
+
up: () => up$6
|
|
1209
1210
|
});
|
|
1210
1211
|
/**
|
|
1211
1212
|
* Migration: Widen scheduled publishing index
|
|
@@ -1214,7 +1215,7 @@ var _030_widen_scheduled_index_exports = /* @__PURE__ */ __exportAll({
|
|
|
1214
1215
|
* Published posts can now have scheduled draft changes, so widen the
|
|
1215
1216
|
* index to cover all rows where scheduled_at IS NOT NULL.
|
|
1216
1217
|
*/
|
|
1217
|
-
async function up$
|
|
1218
|
+
async function up$6(db) {
|
|
1218
1219
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1219
1220
|
for (const tableName of tableNames) {
|
|
1220
1221
|
const table = { name: tableName };
|
|
@@ -1228,7 +1229,7 @@ async function up$5(db) {
|
|
|
1228
1229
|
`.execute(db);
|
|
1229
1230
|
}
|
|
1230
1231
|
}
|
|
1231
|
-
async function down$
|
|
1232
|
+
async function down$6(db) {
|
|
1232
1233
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1233
1234
|
for (const tableName of tableNames) {
|
|
1234
1235
|
const table = { name: tableName };
|
|
@@ -1246,10 +1247,10 @@ async function down$5(db) {
|
|
|
1246
1247
|
//#endregion
|
|
1247
1248
|
//#region src/database/migrations/031_bylines.ts
|
|
1248
1249
|
var _031_bylines_exports = /* @__PURE__ */ __exportAll({
|
|
1249
|
-
down: () => down$
|
|
1250
|
-
up: () => up$
|
|
1250
|
+
down: () => down$5,
|
|
1251
|
+
up: () => up$5
|
|
1251
1252
|
});
|
|
1252
|
-
async function up$
|
|
1253
|
+
async function up$5(db) {
|
|
1253
1254
|
await db.schema.createTable("_emdash_bylines").addColumn("id", "text", (col) => col.primaryKey()).addColumn("slug", "text", (col) => col.notNull().unique()).addColumn("display_name", "text", (col) => col.notNull()).addColumn("bio", "text").addColumn("avatar_media_id", "text", (col) => col.references("media.id").onDelete("set null")).addColumn("website_url", "text").addColumn("user_id", "text", (col) => col.references("users.id").onDelete("set null")).addColumn("is_guest", "integer", (col) => col.notNull().defaultTo(0)).addColumn("created_at", "text", (col) => col.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (col) => col.defaultTo(currentTimestamp(db))).execute();
|
|
1254
1255
|
await sql`
|
|
1255
1256
|
CREATE UNIQUE INDEX ${sql.ref("idx_bylines_user_id_unique")}
|
|
@@ -1281,7 +1282,7 @@ async function up$4(db) {
|
|
|
1281
1282
|
`.execute(db);
|
|
1282
1283
|
}
|
|
1283
1284
|
}
|
|
1284
|
-
async function down$
|
|
1285
|
+
async function down$5(db) {
|
|
1285
1286
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1286
1287
|
for (const tableName of tableNames) {
|
|
1287
1288
|
await sql`
|
|
@@ -1299,8 +1300,8 @@ async function down$4(db) {
|
|
|
1299
1300
|
//#endregion
|
|
1300
1301
|
//#region src/database/migrations/032_rate_limits.ts
|
|
1301
1302
|
var _032_rate_limits_exports = /* @__PURE__ */ __exportAll({
|
|
1302
|
-
down: () => down$
|
|
1303
|
-
up: () => up$
|
|
1303
|
+
down: () => down$4,
|
|
1304
|
+
up: () => up$4
|
|
1304
1305
|
});
|
|
1305
1306
|
/**
|
|
1306
1307
|
* Migration: Rate limits table + device code polling tracking.
|
|
@@ -1311,12 +1312,12 @@ var _032_rate_limits_exports = /* @__PURE__ */ __exportAll({
|
|
|
1311
1312
|
* 2. Add last_polled_at column to _emdash_device_codes for
|
|
1312
1313
|
* RFC 8628 slow_down enforcement.
|
|
1313
1314
|
*/
|
|
1314
|
-
async function up$
|
|
1315
|
+
async function up$4(db) {
|
|
1315
1316
|
await db.schema.createTable("_emdash_rate_limits").addColumn("key", "text", (col) => col.notNull()).addColumn("window", "text", (col) => col.notNull()).addColumn("count", "integer", (col) => col.notNull().defaultTo(1)).addPrimaryKeyConstraint("pk_rate_limits", ["key", "window"]).execute();
|
|
1316
1317
|
await db.schema.createIndex("idx_rate_limits_window").on("_emdash_rate_limits").column("window").execute();
|
|
1317
1318
|
await db.schema.alterTable("_emdash_device_codes").addColumn("last_polled_at", "text").execute();
|
|
1318
1319
|
}
|
|
1319
|
-
async function down$
|
|
1320
|
+
async function down$4(db) {
|
|
1320
1321
|
await db.schema.dropTable("_emdash_rate_limits").execute();
|
|
1321
1322
|
await db.schema.alterTable("_emdash_device_codes").dropColumn("last_polled_at").execute();
|
|
1322
1323
|
}
|
|
@@ -1324,8 +1325,8 @@ async function down$3(db) {
|
|
|
1324
1325
|
//#endregion
|
|
1325
1326
|
//#region src/database/migrations/033_optimize_content_indexes.ts
|
|
1326
1327
|
var _033_optimize_content_indexes_exports = /* @__PURE__ */ __exportAll({
|
|
1327
|
-
down: () => down$
|
|
1328
|
-
up: () => up$
|
|
1328
|
+
down: () => down$3,
|
|
1329
|
+
up: () => up$3
|
|
1329
1330
|
});
|
|
1330
1331
|
/**
|
|
1331
1332
|
* Migration: Optimize content table indexes for D1 performance
|
|
@@ -1338,7 +1339,7 @@ var _033_optimize_content_indexes_exports = /* @__PURE__ */ __exportAll({
|
|
|
1338
1339
|
*
|
|
1339
1340
|
* Impact: Reduces D1 row reads by 90%+ for admin panel operations.
|
|
1340
1341
|
*/
|
|
1341
|
-
async function up$
|
|
1342
|
+
async function up$3(db) {
|
|
1342
1343
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1343
1344
|
for (const tableName of tableNames) {
|
|
1344
1345
|
const table = { name: tableName };
|
|
@@ -1380,7 +1381,7 @@ async function up$2(db) {
|
|
|
1380
1381
|
WHERE status = 'trash'
|
|
1381
1382
|
`.execute(db);
|
|
1382
1383
|
}
|
|
1383
|
-
async function down$
|
|
1384
|
+
async function down$3(db) {
|
|
1384
1385
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1385
1386
|
for (const tableName of tableNames) {
|
|
1386
1387
|
const table = { name: tableName };
|
|
@@ -1413,10 +1414,10 @@ async function down$2(db) {
|
|
|
1413
1414
|
//#endregion
|
|
1414
1415
|
//#region src/database/migrations/034_published_at_index.ts
|
|
1415
1416
|
var _034_published_at_index_exports = /* @__PURE__ */ __exportAll({
|
|
1416
|
-
down: () => down$
|
|
1417
|
-
up: () => up$
|
|
1417
|
+
down: () => down$2,
|
|
1418
|
+
up: () => up$2
|
|
1418
1419
|
});
|
|
1419
|
-
async function up$
|
|
1420
|
+
async function up$2(db) {
|
|
1420
1421
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1421
1422
|
for (const tableName of tableNames) {
|
|
1422
1423
|
const table = { name: tableName };
|
|
@@ -1426,7 +1427,7 @@ async function up$1(db) {
|
|
|
1426
1427
|
`.execute(db);
|
|
1427
1428
|
}
|
|
1428
1429
|
}
|
|
1429
|
-
async function down$
|
|
1430
|
+
async function down$2(db) {
|
|
1430
1431
|
const tableNames = await listTablesLike(db, "ec_%");
|
|
1431
1432
|
for (const tableName of tableNames) {
|
|
1432
1433
|
const table = { name: tableName };
|
|
@@ -1437,8 +1438,8 @@ async function down$1(db) {
|
|
|
1437
1438
|
//#endregion
|
|
1438
1439
|
//#region src/database/migrations/035_bounded_404_log.ts
|
|
1439
1440
|
var _035_bounded_404_log_exports = /* @__PURE__ */ __exportAll({
|
|
1440
|
-
down: () => down,
|
|
1441
|
-
up: () => up
|
|
1441
|
+
down: () => down$1,
|
|
1442
|
+
up: () => up$1
|
|
1442
1443
|
});
|
|
1443
1444
|
/**
|
|
1444
1445
|
* Migration: Bounded 404 logging
|
|
@@ -1456,7 +1457,7 @@ var _035_bounded_404_log_exports = /* @__PURE__ */ __exportAll({
|
|
|
1456
1457
|
* path and summing hits
|
|
1457
1458
|
* - Adds a UNIQUE index on `path` so upsert semantics work
|
|
1458
1459
|
*/
|
|
1459
|
-
async function up(db) {
|
|
1460
|
+
async function up$1(db) {
|
|
1460
1461
|
const hitsExists = await columnExists(db, "_emdash_404_log", "hits");
|
|
1461
1462
|
if (!hitsExists) await db.schema.alterTable("_emdash_404_log").addColumn("hits", "integer", (col) => col.notNull().defaultTo(1)).execute();
|
|
1462
1463
|
if (!await columnExists(db, "_emdash_404_log", "last_seen_at")) await db.schema.alterTable("_emdash_404_log").addColumn("last_seen_at", "text").execute();
|
|
@@ -1505,7 +1506,7 @@ async function up(db) {
|
|
|
1505
1506
|
await db.schema.dropIndex("idx_404_log_path").ifExists().execute();
|
|
1506
1507
|
await db.schema.createIndex("idx_404_log_last_seen").ifNotExists().on("_emdash_404_log").column("last_seen_at").execute();
|
|
1507
1508
|
}
|
|
1508
|
-
async function down(db) {
|
|
1509
|
+
async function down$1(db) {
|
|
1509
1510
|
await db.schema.dropIndex("idx_404_log_last_seen").ifExists().execute();
|
|
1510
1511
|
await db.schema.dropIndex("idx_404_log_path_unique").ifExists().execute();
|
|
1511
1512
|
await db.schema.createIndex("idx_404_log_path").ifNotExists().on("_emdash_404_log").column("path").execute();
|
|
@@ -1513,6 +1514,299 @@ async function down(db) {
|
|
|
1513
1514
|
await db.schema.alterTable("_emdash_404_log").dropColumn("hits").execute();
|
|
1514
1515
|
}
|
|
1515
1516
|
|
|
1517
|
+
//#endregion
|
|
1518
|
+
//#region src/database/migrations/036_i18n_menus_and_taxonomies.ts
|
|
1519
|
+
var _036_i18n_menus_and_taxonomies_exports = /* @__PURE__ */ __exportAll({
|
|
1520
|
+
down: () => down,
|
|
1521
|
+
up: () => up
|
|
1522
|
+
});
|
|
1523
|
+
/**
|
|
1524
|
+
* i18n for menus + taxonomies. Adds `locale` + `translation_group` to system
|
|
1525
|
+
* tables and stores translation_groups (not row ids) in
|
|
1526
|
+
* `_emdash_menu_items.reference_id` and `content_taxonomies.taxonomy_id`.
|
|
1527
|
+
* Backfill locale and column DEFAULTs use the site's configured defaultLocale.
|
|
1528
|
+
*/
|
|
1529
|
+
function getDefaultLocale() {
|
|
1530
|
+
return getI18nConfig()?.defaultLocale ?? "en";
|
|
1531
|
+
}
|
|
1532
|
+
async function up(db) {
|
|
1533
|
+
const defaultLocale = getDefaultLocale();
|
|
1534
|
+
if (isSqlite(db)) {
|
|
1535
|
+
await sql.raw(`PRAGMA foreign_keys = OFF`).execute(db);
|
|
1536
|
+
try {
|
|
1537
|
+
await rebuildMenus(db, defaultLocale);
|
|
1538
|
+
await addItemColumns(db, defaultLocale);
|
|
1539
|
+
await rebuildTaxonomies(db, defaultLocale);
|
|
1540
|
+
await rebuildTaxonomyDefs(db, defaultLocale);
|
|
1541
|
+
await rebuildContentTaxonomies(db);
|
|
1542
|
+
await remapMenuItemRefs(db);
|
|
1543
|
+
} finally {
|
|
1544
|
+
await sql.raw(`PRAGMA foreign_keys = ON`).execute(db);
|
|
1545
|
+
}
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
await pgWiden(db, "_emdash_menus", ["name"], ["name", "locale"], defaultLocale);
|
|
1549
|
+
await pgWiden(db, "_emdash_menu_items", null, null, defaultLocale);
|
|
1550
|
+
await pgWiden(db, "taxonomies", ["name", "slug"], [
|
|
1551
|
+
"name",
|
|
1552
|
+
"slug",
|
|
1553
|
+
"locale"
|
|
1554
|
+
], defaultLocale);
|
|
1555
|
+
await pgWiden(db, "_emdash_taxonomy_defs", ["name"], ["name", "locale"], defaultLocale);
|
|
1556
|
+
await pgRemapContentTaxonomies(db);
|
|
1557
|
+
await remapMenuItemRefs(db);
|
|
1558
|
+
}
|
|
1559
|
+
async function rebuildMenus(db, defaultLocale) {
|
|
1560
|
+
if (await hasColumn(db, "_emdash_menus", "locale")) return;
|
|
1561
|
+
await sql.raw(`DROP TABLE IF EXISTS "_emdash_menus_new"`).execute(db);
|
|
1562
|
+
await db.schema.createTable("_emdash_menus_new").addColumn("id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull()).addColumn("label", "text", (c) => c.notNull()).addColumn("created_at", "text", (c) => c.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (c) => c.defaultTo(currentTimestamp(db))).addColumn("locale", "text", (c) => c.notNull().defaultTo(defaultLocale)).addColumn("translation_group", "text").addUniqueConstraint("_emdash_menus_name_locale_unique", ["name", "locale"]).execute();
|
|
1563
|
+
await sql`
|
|
1564
|
+
INSERT INTO _emdash_menus_new (id, name, label, created_at, updated_at, locale, translation_group)
|
|
1565
|
+
SELECT id, name, label, created_at, updated_at, ${defaultLocale}, id FROM _emdash_menus
|
|
1566
|
+
`.execute(db);
|
|
1567
|
+
await db.schema.dropTable("_emdash_menus").execute();
|
|
1568
|
+
await sql`ALTER TABLE _emdash_menus_new RENAME TO _emdash_menus`.execute(db);
|
|
1569
|
+
await db.schema.createIndex("idx__emdash_menus_locale").on("_emdash_menus").column("locale").execute();
|
|
1570
|
+
await db.schema.createIndex("idx__emdash_menus_translation_group").on("_emdash_menus").column("translation_group").execute();
|
|
1571
|
+
}
|
|
1572
|
+
async function addItemColumns(db, defaultLocale) {
|
|
1573
|
+
if (await hasColumn(db, "_emdash_menu_items", "locale")) return;
|
|
1574
|
+
await db.schema.alterTable("_emdash_menu_items").addColumn("locale", "text", (c) => c.notNull().defaultTo(defaultLocale)).execute();
|
|
1575
|
+
await db.schema.alterTable("_emdash_menu_items").addColumn("translation_group", "text").execute();
|
|
1576
|
+
await sql`UPDATE _emdash_menu_items SET translation_group = id`.execute(db);
|
|
1577
|
+
await db.schema.createIndex("idx__emdash_menu_items_locale").on("_emdash_menu_items").column("locale").execute();
|
|
1578
|
+
await db.schema.createIndex("idx__emdash_menu_items_translation_group").on("_emdash_menu_items").column("translation_group").execute();
|
|
1579
|
+
}
|
|
1580
|
+
async function rebuildTaxonomies(db, defaultLocale) {
|
|
1581
|
+
if (await hasColumn(db, "taxonomies", "locale")) return;
|
|
1582
|
+
await sql.raw(`DROP TABLE IF EXISTS "taxonomies_new"`).execute(db);
|
|
1583
|
+
await sql`DROP INDEX IF EXISTS idx_taxonomies_name`.execute(db);
|
|
1584
|
+
await db.schema.createTable("taxonomies_new").addColumn("id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull()).addColumn("slug", "text", (c) => c.notNull()).addColumn("label", "text", (c) => c.notNull()).addColumn("parent_id", "text").addColumn("data", "text").addColumn("locale", "text", (c) => c.notNull().defaultTo(defaultLocale)).addColumn("translation_group", "text").addUniqueConstraint("taxonomies_name_slug_locale_unique", [
|
|
1585
|
+
"name",
|
|
1586
|
+
"slug",
|
|
1587
|
+
"locale"
|
|
1588
|
+
]).addForeignKeyConstraint("taxonomies_parent_fk", ["parent_id"], "taxonomies", ["id"], (cb) => cb.onDelete("set null")).execute();
|
|
1589
|
+
await sql`
|
|
1590
|
+
INSERT INTO taxonomies_new (id, name, slug, label, parent_id, data, locale, translation_group)
|
|
1591
|
+
SELECT id, name, slug, label, parent_id, data, ${defaultLocale}, id FROM taxonomies
|
|
1592
|
+
`.execute(db);
|
|
1593
|
+
await db.schema.dropTable("taxonomies").execute();
|
|
1594
|
+
await sql`ALTER TABLE taxonomies_new RENAME TO taxonomies`.execute(db);
|
|
1595
|
+
await db.schema.createIndex("idx_taxonomies_name").on("taxonomies").column("name").execute();
|
|
1596
|
+
await db.schema.createIndex("idx_taxonomies_locale").on("taxonomies").column("locale").execute();
|
|
1597
|
+
await db.schema.createIndex("idx_taxonomies_translation_group").on("taxonomies").column("translation_group").execute();
|
|
1598
|
+
}
|
|
1599
|
+
async function rebuildTaxonomyDefs(db, defaultLocale) {
|
|
1600
|
+
if (await hasColumn(db, "_emdash_taxonomy_defs", "locale")) return;
|
|
1601
|
+
await sql.raw(`DROP TABLE IF EXISTS "_emdash_taxonomy_defs_new"`).execute(db);
|
|
1602
|
+
await db.schema.createTable("_emdash_taxonomy_defs_new").addColumn("id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull()).addColumn("label", "text", (c) => c.notNull()).addColumn("label_singular", "text").addColumn("hierarchical", "integer", (c) => c.defaultTo(0)).addColumn("collections", "text").addColumn("created_at", "text", (c) => c.defaultTo(currentTimestamp(db))).addColumn("locale", "text", (c) => c.notNull().defaultTo(defaultLocale)).addColumn("translation_group", "text").addUniqueConstraint("_emdash_taxonomy_defs_name_locale_unique", ["name", "locale"]).execute();
|
|
1603
|
+
await sql`
|
|
1604
|
+
INSERT INTO _emdash_taxonomy_defs_new
|
|
1605
|
+
(id, name, label, label_singular, hierarchical, collections, created_at, locale, translation_group)
|
|
1606
|
+
SELECT id, name, label, label_singular, hierarchical, collections, created_at, ${defaultLocale}, id
|
|
1607
|
+
FROM _emdash_taxonomy_defs
|
|
1608
|
+
`.execute(db);
|
|
1609
|
+
await db.schema.dropTable("_emdash_taxonomy_defs").execute();
|
|
1610
|
+
await sql`ALTER TABLE _emdash_taxonomy_defs_new RENAME TO _emdash_taxonomy_defs`.execute(db);
|
|
1611
|
+
await db.schema.createIndex("idx__emdash_taxonomy_defs_locale").on("_emdash_taxonomy_defs").column("locale").execute();
|
|
1612
|
+
await db.schema.createIndex("idx__emdash_taxonomy_defs_translation_group").on("_emdash_taxonomy_defs").column("translation_group").execute();
|
|
1613
|
+
}
|
|
1614
|
+
async function rebuildContentTaxonomies(db) {
|
|
1615
|
+
if ((await sql`PRAGMA foreign_key_list(content_taxonomies)`.execute(db)).rows.length === 0) return;
|
|
1616
|
+
await sql.raw(`DROP TABLE IF EXISTS "content_taxonomies_new"`).execute(db);
|
|
1617
|
+
await db.schema.createTable("content_taxonomies_new").addColumn("collection", "text", (c) => c.notNull()).addColumn("entry_id", "text", (c) => c.notNull()).addColumn("taxonomy_id", "text", (c) => c.notNull()).addPrimaryKeyConstraint("content_taxonomies_pk", [
|
|
1618
|
+
"collection",
|
|
1619
|
+
"entry_id",
|
|
1620
|
+
"taxonomy_id"
|
|
1621
|
+
]).execute();
|
|
1622
|
+
await sql`
|
|
1623
|
+
INSERT OR IGNORE INTO content_taxonomies_new (collection, entry_id, taxonomy_id)
|
|
1624
|
+
SELECT ct.collection, ct.entry_id, COALESCE(
|
|
1625
|
+
(SELECT t.translation_group FROM taxonomies t WHERE t.id = ct.taxonomy_id),
|
|
1626
|
+
ct.taxonomy_id
|
|
1627
|
+
)
|
|
1628
|
+
FROM content_taxonomies ct
|
|
1629
|
+
`.execute(db);
|
|
1630
|
+
await db.schema.dropTable("content_taxonomies").execute();
|
|
1631
|
+
await sql`ALTER TABLE content_taxonomies_new RENAME TO content_taxonomies`.execute(db);
|
|
1632
|
+
}
|
|
1633
|
+
async function remapMenuItemRefs(db) {
|
|
1634
|
+
const collections = await sql`SELECT slug FROM _emdash_collections`.execute(db);
|
|
1635
|
+
for (const { slug } of collections.rows) {
|
|
1636
|
+
validateIdentifier(slug, "collection slug");
|
|
1637
|
+
const ec = sql.ref(`ec_${slug}`);
|
|
1638
|
+
await sql`
|
|
1639
|
+
UPDATE _emdash_menu_items SET reference_id = (
|
|
1640
|
+
SELECT translation_group FROM ${ec} WHERE ${ec}.id = _emdash_menu_items.reference_id
|
|
1641
|
+
)
|
|
1642
|
+
WHERE reference_collection = ${slug} AND reference_id IS NOT NULL
|
|
1643
|
+
AND EXISTS (SELECT 1 FROM ${ec} WHERE ${ec}.id = _emdash_menu_items.reference_id)
|
|
1644
|
+
`.execute(db);
|
|
1645
|
+
}
|
|
1646
|
+
await sql`
|
|
1647
|
+
UPDATE _emdash_menu_items SET reference_id = (
|
|
1648
|
+
SELECT translation_group FROM taxonomies WHERE taxonomies.id = _emdash_menu_items.reference_id
|
|
1649
|
+
)
|
|
1650
|
+
WHERE type = 'taxonomy' AND reference_id IS NOT NULL
|
|
1651
|
+
AND EXISTS (SELECT 1 FROM taxonomies WHERE taxonomies.id = _emdash_menu_items.reference_id)
|
|
1652
|
+
`.execute(db);
|
|
1653
|
+
}
|
|
1654
|
+
async function pgWiden(db, table, oldCols, newCols, defaultLocale) {
|
|
1655
|
+
validateSystemIdent(table);
|
|
1656
|
+
const ref = sql.ref(table);
|
|
1657
|
+
await sql`ALTER TABLE ${ref} ADD COLUMN IF NOT EXISTS locale TEXT NOT NULL DEFAULT ${sql.lit(defaultLocale)}`.execute(db);
|
|
1658
|
+
await sql`ALTER TABLE ${ref} ADD COLUMN IF NOT EXISTS translation_group TEXT`.execute(db);
|
|
1659
|
+
await sql`UPDATE ${ref} SET translation_group = id WHERE translation_group IS NULL`.execute(db);
|
|
1660
|
+
await sql`CREATE INDEX IF NOT EXISTS ${sql.ref(`idx_${table}_locale`)} ON ${ref} (locale)`.execute(db);
|
|
1661
|
+
await sql`
|
|
1662
|
+
CREATE INDEX IF NOT EXISTS ${sql.ref(`idx_${table}_translation_group`)} ON ${ref} (translation_group)
|
|
1663
|
+
`.execute(db);
|
|
1664
|
+
if (!oldCols || !newCols) return;
|
|
1665
|
+
for (const c of [...oldCols, ...newCols]) validateSystemIdent(c);
|
|
1666
|
+
const cons = await sql`
|
|
1667
|
+
SELECT conname FROM pg_constraint c
|
|
1668
|
+
WHERE c.conrelid = ${table}::regclass AND c.contype = 'u'
|
|
1669
|
+
AND array_length(c.conkey, 1) = ${oldCols.length}
|
|
1670
|
+
AND (
|
|
1671
|
+
SELECT array_agg(a.attname ORDER BY pos.ord)
|
|
1672
|
+
FROM unnest(c.conkey) WITH ORDINALITY AS pos(attnum, ord)
|
|
1673
|
+
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = pos.attnum
|
|
1674
|
+
)::text[] = ${oldCols}::text[]
|
|
1675
|
+
`.execute(db);
|
|
1676
|
+
for (const c of cons.rows) await sql`ALTER TABLE ${ref} DROP CONSTRAINT ${sql.ref(c.conname)}`.execute(db);
|
|
1677
|
+
const cols = sql.join(newCols.map((c) => sql.ref(c)), sql`, `);
|
|
1678
|
+
await sql`
|
|
1679
|
+
ALTER TABLE ${ref}
|
|
1680
|
+
ADD CONSTRAINT ${sql.ref(`${table}_${newCols.join("_")}_unique`)} UNIQUE (${cols})
|
|
1681
|
+
`.execute(db);
|
|
1682
|
+
}
|
|
1683
|
+
async function pgRemapContentTaxonomies(db) {
|
|
1684
|
+
const fks = await sql`
|
|
1685
|
+
SELECT conname FROM pg_constraint
|
|
1686
|
+
WHERE conrelid = 'content_taxonomies'::regclass AND contype = 'f'
|
|
1687
|
+
`.execute(db);
|
|
1688
|
+
for (const c of fks.rows) await sql`ALTER TABLE content_taxonomies DROP CONSTRAINT ${sql.ref(c.conname)}`.execute(db);
|
|
1689
|
+
await sql`
|
|
1690
|
+
UPDATE content_taxonomies SET taxonomy_id = t.translation_group
|
|
1691
|
+
FROM taxonomies t WHERE t.id = content_taxonomies.taxonomy_id
|
|
1692
|
+
`.execute(db);
|
|
1693
|
+
}
|
|
1694
|
+
async function hasColumn(db, table, column) {
|
|
1695
|
+
return (await sql`PRAGMA table_info(${sql.ref(table)})`.execute(db)).rows.some((r) => r.name === column);
|
|
1696
|
+
}
|
|
1697
|
+
const SYSTEM_IDENT = /^[_a-z][a-z0-9_]*$/;
|
|
1698
|
+
function validateSystemIdent(name) {
|
|
1699
|
+
if (!SYSTEM_IDENT.test(name)) throw new Error(`Invalid identifier: "${name}"`);
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* down() is destructive on multi-locale installs (dropping `locale` collapses
|
|
1703
|
+
* translated rows onto an ambiguous unique key). Refuse to run when any row
|
|
1704
|
+
* sits at a locale other than the configured defaultLocale.
|
|
1705
|
+
*/
|
|
1706
|
+
async function assertSingleLocale(db, defaultLocale) {
|
|
1707
|
+
for (const table of [
|
|
1708
|
+
"_emdash_menus",
|
|
1709
|
+
"_emdash_menu_items",
|
|
1710
|
+
"taxonomies",
|
|
1711
|
+
"_emdash_taxonomy_defs"
|
|
1712
|
+
]) {
|
|
1713
|
+
validateSystemIdent(table);
|
|
1714
|
+
const result = await sql`
|
|
1715
|
+
SELECT COUNT(*) AS count FROM ${sql.ref(table)} WHERE locale != ${defaultLocale}
|
|
1716
|
+
`.execute(db);
|
|
1717
|
+
const count = Number(result.rows[0]?.count ?? 0);
|
|
1718
|
+
if (count > 0) throw new Error(`Cannot revert migration 036_i18n_menus_and_taxonomies: ${count} row(s) in "${table}" use a non-default locale (defaultLocale="${defaultLocale}"). Reverting would drop them silently. Export translations first (or delete them) and re-run the rollback. See packages/core/src/database/migrations/036_i18n_menus_and_taxonomies.ts.`);
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
async function down(db) {
|
|
1722
|
+
const defaultLocale = getDefaultLocale();
|
|
1723
|
+
await assertSingleLocale(db, defaultLocale);
|
|
1724
|
+
const widenedTables = [
|
|
1725
|
+
"_emdash_menus",
|
|
1726
|
+
"_emdash_menu_items",
|
|
1727
|
+
"taxonomies",
|
|
1728
|
+
"_emdash_taxonomy_defs"
|
|
1729
|
+
];
|
|
1730
|
+
if (isSqlite(db)) {
|
|
1731
|
+
await sql.raw(`PRAGMA foreign_keys = OFF`).execute(db);
|
|
1732
|
+
try {
|
|
1733
|
+
for (const t of widenedTables) {
|
|
1734
|
+
await sql.raw(`DROP INDEX IF EXISTS idx_${t}_locale`).execute(db);
|
|
1735
|
+
await sql.raw(`DROP INDEX IF EXISTS idx_${t}_translation_group`).execute(db);
|
|
1736
|
+
}
|
|
1737
|
+
await rebuildContentTaxonomiesDown(db, defaultLocale);
|
|
1738
|
+
await rebuildMenusDown(db);
|
|
1739
|
+
await rebuildMenuItemsDown(db);
|
|
1740
|
+
await rebuildTaxonomiesDown(db);
|
|
1741
|
+
await rebuildTaxonomyDefsDown(db);
|
|
1742
|
+
} finally {
|
|
1743
|
+
await sql.raw(`PRAGMA foreign_keys = ON`).execute(db);
|
|
1744
|
+
}
|
|
1745
|
+
return;
|
|
1746
|
+
}
|
|
1747
|
+
for (const t of widenedTables) {
|
|
1748
|
+
await sql.raw(`DROP INDEX IF EXISTS idx_${t}_locale`).execute(db);
|
|
1749
|
+
await sql.raw(`DROP INDEX IF EXISTS idx_${t}_translation_group`).execute(db);
|
|
1750
|
+
await sql.raw(`ALTER TABLE "${t}" DROP COLUMN IF EXISTS locale`).execute(db);
|
|
1751
|
+
await sql.raw(`ALTER TABLE "${t}" DROP COLUMN IF EXISTS translation_group`).execute(db);
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
async function rebuildContentTaxonomiesDown(db, defaultLocale) {
|
|
1755
|
+
await sql.raw(`DROP TABLE IF EXISTS "content_taxonomies_new"`).execute(db);
|
|
1756
|
+
await db.schema.createTable("content_taxonomies_new").addColumn("collection", "text", (c) => c.notNull()).addColumn("entry_id", "text", (c) => c.notNull()).addColumn("taxonomy_id", "text", (c) => c.notNull()).addPrimaryKeyConstraint("content_taxonomies_pk", [
|
|
1757
|
+
"collection",
|
|
1758
|
+
"entry_id",
|
|
1759
|
+
"taxonomy_id"
|
|
1760
|
+
]).addForeignKeyConstraint("content_taxonomies_taxonomy_fk", ["taxonomy_id"], "taxonomies", ["id"], (cb) => cb.onDelete("cascade")).execute();
|
|
1761
|
+
await sql`
|
|
1762
|
+
INSERT OR IGNORE INTO content_taxonomies_new (collection, entry_id, taxonomy_id)
|
|
1763
|
+
SELECT ct.collection, ct.entry_id, COALESCE(
|
|
1764
|
+
(SELECT t.id FROM taxonomies t WHERE t.translation_group = ct.taxonomy_id AND t.locale = ${defaultLocale}),
|
|
1765
|
+
ct.taxonomy_id
|
|
1766
|
+
)
|
|
1767
|
+
FROM content_taxonomies ct
|
|
1768
|
+
`.execute(db);
|
|
1769
|
+
await db.schema.dropTable("content_taxonomies").execute();
|
|
1770
|
+
await sql`ALTER TABLE content_taxonomies_new RENAME TO content_taxonomies`.execute(db);
|
|
1771
|
+
}
|
|
1772
|
+
async function rebuildMenusDown(db) {
|
|
1773
|
+
await sql.raw(`DROP TABLE IF EXISTS "_emdash_menus_old"`).execute(db);
|
|
1774
|
+
await db.schema.createTable("_emdash_menus_old").addColumn("id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull().unique()).addColumn("label", "text", (c) => c.notNull()).addColumn("created_at", "text", (c) => c.defaultTo(currentTimestamp(db))).addColumn("updated_at", "text", (c) => c.defaultTo(currentTimestamp(db))).execute();
|
|
1775
|
+
await sql`
|
|
1776
|
+
INSERT INTO _emdash_menus_old (id, name, label, created_at, updated_at)
|
|
1777
|
+
SELECT id, name, label, created_at, updated_at FROM _emdash_menus
|
|
1778
|
+
`.execute(db);
|
|
1779
|
+
await db.schema.dropTable("_emdash_menus").execute();
|
|
1780
|
+
await sql`ALTER TABLE _emdash_menus_old RENAME TO _emdash_menus`.execute(db);
|
|
1781
|
+
}
|
|
1782
|
+
async function rebuildMenuItemsDown(db) {
|
|
1783
|
+
await sql.raw(`ALTER TABLE _emdash_menu_items DROP COLUMN locale`).execute(db);
|
|
1784
|
+
await sql.raw(`ALTER TABLE _emdash_menu_items DROP COLUMN translation_group`).execute(db);
|
|
1785
|
+
}
|
|
1786
|
+
async function rebuildTaxonomiesDown(db) {
|
|
1787
|
+
await sql.raw(`DROP TABLE IF EXISTS "taxonomies_old"`).execute(db);
|
|
1788
|
+
await db.schema.createTable("taxonomies_old").addColumn("id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull()).addColumn("slug", "text", (c) => c.notNull()).addColumn("label", "text", (c) => c.notNull()).addColumn("parent_id", "text").addColumn("data", "text").addUniqueConstraint("taxonomies_name_slug_unique", ["name", "slug"]).addForeignKeyConstraint("taxonomies_parent_fk", ["parent_id"], "taxonomies_old", ["id"], (cb) => cb.onDelete("set null")).execute();
|
|
1789
|
+
await sql`
|
|
1790
|
+
INSERT INTO taxonomies_old (id, name, slug, label, parent_id, data)
|
|
1791
|
+
SELECT id, name, slug, label, parent_id, data FROM taxonomies
|
|
1792
|
+
`.execute(db);
|
|
1793
|
+
await db.schema.dropTable("taxonomies").execute();
|
|
1794
|
+
await sql`ALTER TABLE taxonomies_old RENAME TO taxonomies`.execute(db);
|
|
1795
|
+
await db.schema.createIndex("idx_taxonomies_name").on("taxonomies").column("name").execute();
|
|
1796
|
+
}
|
|
1797
|
+
async function rebuildTaxonomyDefsDown(db) {
|
|
1798
|
+
await sql.raw(`DROP TABLE IF EXISTS "_emdash_taxonomy_defs_old"`).execute(db);
|
|
1799
|
+
await db.schema.createTable("_emdash_taxonomy_defs_old").addColumn("id", "text", (c) => c.primaryKey()).addColumn("name", "text", (c) => c.notNull().unique()).addColumn("label", "text", (c) => c.notNull()).addColumn("label_singular", "text").addColumn("hierarchical", "integer", (c) => c.defaultTo(0)).addColumn("collections", "text").addColumn("created_at", "text", (c) => c.defaultTo(currentTimestamp(db))).execute();
|
|
1800
|
+
await sql`
|
|
1801
|
+
INSERT INTO _emdash_taxonomy_defs_old
|
|
1802
|
+
(id, name, label, label_singular, hierarchical, collections, created_at)
|
|
1803
|
+
SELECT id, name, label, label_singular, hierarchical, collections, created_at
|
|
1804
|
+
FROM _emdash_taxonomy_defs
|
|
1805
|
+
`.execute(db);
|
|
1806
|
+
await db.schema.dropTable("_emdash_taxonomy_defs").execute();
|
|
1807
|
+
await sql`ALTER TABLE _emdash_taxonomy_defs_old RENAME TO _emdash_taxonomy_defs`.execute(db);
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1516
1810
|
//#endregion
|
|
1517
1811
|
//#region src/database/migrations/runner.ts
|
|
1518
1812
|
const MIGRATIONS = Object.freeze({
|
|
@@ -1549,7 +1843,8 @@ const MIGRATIONS = Object.freeze({
|
|
|
1549
1843
|
"032_rate_limits": _032_rate_limits_exports,
|
|
1550
1844
|
"033_optimize_content_indexes": _033_optimize_content_indexes_exports,
|
|
1551
1845
|
"034_published_at_index": _034_published_at_index_exports,
|
|
1552
|
-
"035_bounded_404_log": _035_bounded_404_log_exports
|
|
1846
|
+
"035_bounded_404_log": _035_bounded_404_log_exports,
|
|
1847
|
+
"036_i18n_menus_and_taxonomies": _036_i18n_menus_and_taxonomies_exports
|
|
1553
1848
|
});
|
|
1554
1849
|
/** Total number of registered migrations. Exported for use in tests. */
|
|
1555
1850
|
const MIGRATION_COUNT = Object.keys(MIGRATIONS).length;
|
|
@@ -1746,4 +2041,4 @@ async function rollbackMigration(db) {
|
|
|
1746
2041
|
|
|
1747
2042
|
//#endregion
|
|
1748
2043
|
export { __exportAll as i, rollbackMigration as n, runMigrations as r, getMigrationStatus as t };
|
|
1749
|
-
//# sourceMappingURL=runner-
|
|
2044
|
+
//# sourceMappingURL=runner-DMnlIkh4.mjs.map
|