UNPKG

@lucidcms/core

Version:

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

1 lines 2.44 kB
{"version":3,"file":"determine-column-mods.mjs","names":[],"sources":["../../../../src/libs/collection/migration/determine-column-mods.ts"],"sourcesContent":["import type { CollectionSchemaColumn } from \"../../../libs/collection/schema/types.js\";\nimport type { InferredColumn } from \"../../../types.js\";\nimport defaultValuesEqual from \"../helpers/default-values-equal.js\";\nimport foreignKeysEqual from \"../helpers/foreign-keys-equal.js\";\nimport type { ModifyColumnOperation } from \"./types.js\";\n\n/**\n * Determines the modifications required to convert an existing column to a new column\n */\nconst determineColumnMods = (\n\tcollectionInfCol: CollectionSchemaColumn,\n\tdbInfCol: CollectionSchemaColumn | InferredColumn,\n): ModifyColumnOperation | null => {\n\tconst changes: ModifyColumnOperation[\"changes\"] = {};\n\n\tif (collectionInfCol.type !== dbInfCol.type) {\n\t\tchanges.type = {\n\t\t\tfrom: dbInfCol.type,\n\t\t\tto: collectionInfCol.type,\n\t\t};\n\t}\n\n\tif (collectionInfCol.nullable !== dbInfCol.nullable) {\n\t\tchanges.nullable = {\n\t\t\tfrom: dbInfCol.nullable,\n\t\t\tto: collectionInfCol.nullable,\n\t\t};\n\t}\n\n\tif (!defaultValuesEqual(collectionInfCol.default, dbInfCol.default)) {\n\t\tchanges.default = {\n\t\t\tfrom: dbInfCol.default,\n\t\t\tto: collectionInfCol.default,\n\t\t};\n\t}\n\n\tif (!foreignKeysEqual(collectionInfCol.foreignKey, dbInfCol.foreignKey)) {\n\t\tchanges.foreignKey = {\n\t\t\tfrom: dbInfCol.foreignKey,\n\t\t\tto: collectionInfCol.foreignKey,\n\t\t};\n\t}\n\n\tif (collectionInfCol.unique !== dbInfCol.unique) {\n\t\tchanges.unique = {\n\t\t\tfrom: dbInfCol.unique,\n\t\t\tto: collectionInfCol.unique,\n\t\t};\n\t}\n\n\treturn Object.keys(changes).length > 0\n\t\t? {\n\t\t\t\ttype: \"modify\",\n\t\t\t\tcolumn: collectionInfCol,\n\t\t\t\tchanges,\n\t\t\t}\n\t\t: null;\n};\n\nexport default determineColumnMods;\n"],"mappings":"oGASA,MAAM,GACL,EACA,IACkC,CAClC,IAAM,EAA4C,CAAC,EAqCnD,OAnCI,EAAiB,OAAS,EAAS,OACtC,EAAQ,KAAO,CACd,KAAM,EAAS,KACf,GAAI,EAAiB,IACtB,GAGG,EAAiB,WAAa,EAAS,WAC1C,EAAQ,SAAW,CAClB,KAAM,EAAS,SACf,GAAI,EAAiB,QACtB,GAGI,EAAmB,EAAiB,QAAS,EAAS,OAAO,IACjE,EAAQ,QAAU,CACjB,KAAM,EAAS,QACf,GAAI,EAAiB,OACtB,GAGI,EAAiB,EAAiB,WAAY,EAAS,UAAU,IACrE,EAAQ,WAAa,CACpB,KAAM,EAAS,WACf,GAAI,EAAiB,UACtB,GAGG,EAAiB,SAAW,EAAS,SACxC,EAAQ,OAAS,CAChB,KAAM,EAAS,OACf,GAAI,EAAiB,MACtB,GAGM,OAAO,KAAK,CAAO,CAAC,CAAC,OAAS,EAClC,CACA,KAAM,SACN,OAAQ,EACR,SACD,EACC,IACJ"}