@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 2.3 kB
Source Map (JSON)
{"version":3,"file":"plan-collection-migrations.mjs","names":[],"sources":["../../../src/libs/collection/plan-collection-migrations.ts"],"sourcesContent":["import type { ServiceFn } from \"../../types.js\";\nimport generateMigrationPlan from \"./migration/generate-migration-plan.js\";\nimport type {\n\tCollectionMigrationPlan,\n\tPlannedCollectionMigration,\n} from \"./migration/types.js\";\nimport inferSchema from \"./schema/infer-schema.js\";\n\n/**\n * Introspects the database and builds the exact supported operations needed to\n * bring Lucid-owned tables in line with the configured collections.\n */\nconst planCollectionMigrations: ServiceFn<[], CollectionMigrationPlan> = async (\n\tcontext,\n) => {\n\tconst dbSchema = await context.config.db.inferSchema(context.db.client);\n\tconst collections: PlannedCollectionMigration[] = [];\n\n\tfor (const collection of context.config.collections) {\n\t\tconst schemaRes = inferSchema(collection, context.config.db);\n\t\tif (schemaRes.error) return schemaRes;\n\t\tconst configuredTableNames = new Set(\n\t\t\tschemaRes.data.tables.map((table) => table.name),\n\t\t);\n\t\tconst existingTables = dbSchema.filter((table) =>\n\t\t\tconfiguredTableNames.has(table.name),\n\t\t);\n\t\tconst migrationPlanRes = generateMigrationPlan({\n\t\t\tschemas: {\n\t\t\t\texisting: existingTables,\n\t\t\t\tcurrent: schemaRes.data,\n\t\t\t},\n\t\t\tdb: context.config.db,\n\t\t});\n\t\tif (migrationPlanRes.error) return migrationPlanRes;\n\n\t\tcollections.push({\n\t\t\tmigrationPlan: migrationPlanRes.data,\n\t\t\tinferredSchema: schemaRes.data,\n\t\t});\n\t}\n\n\treturn {\n\t\tdata: { collections },\n\t\terror: undefined,\n\t};\n};\n\nexport default planCollectionMigrations;\n"],"mappings":"gGAYA,MAAM,EAAmE,KACxE,IACI,CACJ,IAAM,EAAW,MAAM,EAAQ,OAAO,GAAG,YAAY,EAAQ,GAAG,MAAM,EAChE,EAA4C,CAAC,EAEnD,IAAK,IAAM,KAAc,EAAQ,OAAO,YAAa,CACpD,IAAM,EAAY,EAAY,EAAY,EAAQ,OAAO,EAAE,EAC3D,GAAI,EAAU,MAAO,OAAO,EAC5B,IAAM,EAAuB,IAAI,IAChC,EAAU,KAAK,OAAO,IAAK,GAAU,EAAM,IAAI,CAChD,EAIM,EAAmB,EAAsB,CAC9C,QAAS,CACR,SALqB,EAAS,OAAQ,GACvC,EAAqB,IAAI,EAAM,IAAI,CAIX,EACvB,QAAS,EAAU,IACpB,EACA,GAAI,EAAQ,OAAO,EACpB,CAAC,EACD,GAAI,EAAiB,MAAO,OAAO,EAEnC,EAAY,KAAK,CAChB,cAAe,EAAiB,KAChC,eAAgB,EAAU,IAC3B,CAAC,CACF,CAEA,MAAO,CACN,KAAM,CAAE,aAAY,EACpB,MAAO,IAAA,EACR,CACD"}