UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 6.91 kB
{"version":3,"file":"versions-table.mjs","names":[],"sources":["../../../../../src/libs/collection/schema/tables/versions-table.ts"],"sourcesContent":["import type CollectionBuilder from \"../../../../libs/collection/builders/collection-builder/index.js\";\nimport type DatabaseAdapter from \"../../../../libs/db/adapter-base.js\";\nimport type { ServiceResponse } from \"../../../../types.js\";\nimport buildSchemaIndex from \"../../helpers/build-schema-index.js\";\nimport buildTableName from \"../../helpers/build-table-name.js\";\nimport type { CollectionSchemaTable } from \"../types.js\";\n\n/**\n * Returns the versions table\n */\nconst createVersionsTable = (props: {\n\tcollection: CollectionBuilder;\n\tdb: DatabaseAdapter;\n}): Awaited<\n\tServiceResponse<{\n\t\tschema: CollectionSchemaTable;\n\t}>\n> => {\n\tconst tableNameRes = buildTableName(\n\t\t\"versions\",\n\t\t{\n\t\t\tcollection: props.collection.key,\n\t\t},\n\t\tprops.db.config.tableNameByteLimit,\n\t);\n\tconst documentTableRes = buildTableName(\n\t\t\"document\",\n\t\t{\n\t\t\tcollection: props.collection.key,\n\t\t},\n\t\tprops.db.config.tableNameByteLimit,\n\t);\n\n\tif (tableNameRes.error) return tableNameRes;\n\tif (documentTableRes.error) return documentTableRes;\n\tconst tableName = tableNameRes.data.name;\n\n\treturn {\n\t\tdata: {\n\t\t\tschema: {\n\t\t\t\tname: tableName,\n\t\t\t\trawName: tableNameRes.data.rawName,\n\t\t\t\ttype: \"versions\",\n\t\t\t\tkey: {\n\t\t\t\t\tcollection: props.collection.key,\n\t\t\t\t},\n\t\t\t\tcolumns: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"id\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"primary\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tprimary: true,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"collection_key\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"text\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_collections\",\n\t\t\t\t\t\t\tcolumn: \"key\",\n\t\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"collection_migration_id\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_collection_migrations\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"restrict\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"document_id\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: documentTableRes.data.name,\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"cascade\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"type\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"text\"),\n\t\t\t\t\t\tdefault: \"latest\",\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"promoted_from\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: tableNameRes.data.name,\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"set null\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"content_id\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"text\"),\n\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"created_by\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_users\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"set null\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"updated_by\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"integer\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tforeignKey: {\n\t\t\t\t\t\t\ttable: \"lucid_users\",\n\t\t\t\t\t\t\tcolumn: \"id\",\n\t\t\t\t\t\t\tonDelete: \"set null\",\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"created_at\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"timestamp\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tdefault: props.db.getDefault(\"timestamp\", \"now\"),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"updated_at\",\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t\ttype: props.db.getDataType(\"timestamp\"),\n\t\t\t\t\t\tnullable: true,\n\t\t\t\t\t\tdefault: props.db.getDefault(\"timestamp\", \"now\"),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tindexes: [\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"document_id\", \"type\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t\tbuildSchemaIndex({\n\t\t\t\t\t\tdb: props.db,\n\t\t\t\t\t\ttableName,\n\t\t\t\t\t\tcolumns: [\"document_id\", \"type\", \"created_at\"],\n\t\t\t\t\t\tsource: \"core\",\n\t\t\t\t\t}),\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\terror: undefined,\n\t};\n};\n\nexport default createVersionsTable;\n"],"mappings":"sGAUA,MAAM,EAAuB,GAOxB,CACJ,IAAM,EAAe,EACpB,WACA,CACC,WAAY,EAAM,WAAW,GAC9B,EACA,EAAM,GAAG,OAAO,kBACjB,EACM,EAAmB,EACxB,WACA,CACC,WAAY,EAAM,WAAW,GAC9B,EACA,EAAM,GAAG,OAAO,kBACjB,EAEA,GAAI,EAAa,MAAO,OAAO,EAC/B,GAAI,EAAiB,MAAO,OAAO,EACnC,IAAM,EAAY,EAAa,KAAK,KAEpC,MAAO,CACN,KAAM,CACL,OAAQ,CACP,KAAM,EACN,QAAS,EAAa,KAAK,QAC3B,KAAM,WACN,IAAK,CACJ,WAAY,EAAM,WAAW,GAC9B,EACA,QAAS,CACR,CACC,KAAM,KACN,OAAQ,OACR,KAAM,EAAM,GAAG,YAAY,SAAS,EACpC,SAAU,GACV,QAAS,EACV,EACA,CACC,KAAM,iBACN,OAAQ,OACR,KAAM,EAAM,GAAG,YAAY,MAAM,EACjC,SAAU,GACV,WAAY,CACX,MAAO,oBACP,OAAQ,MACR,SAAU,SACX,CACD,EACA,CACC,KAAM,0BACN,OAAQ,OACR,KAAM,EAAM,GAAG,YAAY,SAAS,EACpC,SAAU,GACV,WAAY,CACX,MAAO,8BACP,OAAQ,KACR,SAAU,UACX,CACD,EACA,CACC,KAAM,cACN,OAAQ,OACR,K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