@autofleet/sadot 1.6.0-alpha.1 → 1.6.0-alpha.2
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/migrations/001-create-core-tables.cjs +1 -1
- package/dist/migrations/001-create-core-tables.cjs.map +1 -1
- package/dist/migrations/001-create-core-tables.js +1 -1
- package/dist/migrations/001-create-core-tables.js.map +1 -1
- package/dist/migrations/index.cjs +1 -1
- package/dist/migrations/index.cjs.map +1 -1
- package/dist/migrations/index.js +1 -1
- package/dist/migrations/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -12,7 +12,7 @@ const e=async({context:e})=>{let{sequelize:t}=e;await t.query(`
|
|
|
12
12
|
"required" BOOLEAN DEFAULT false,
|
|
13
13
|
"disabled" BOOLEAN DEFAULT false,
|
|
14
14
|
"default_value" JSONB,
|
|
15
|
-
"
|
|
15
|
+
"block_editing_from_u_i" BOOLEAN NOT NULL DEFAULT false,
|
|
16
16
|
"created_at" TIMESTAMPTZ NOT NULL,
|
|
17
17
|
"updated_at" TIMESTAMPTZ,
|
|
18
18
|
"deleted_at" TIMESTAMPTZ,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"001-create-core-tables.cjs","names":["up: MigrationFn<QueryInterface>","down: MigrationFn<QueryInterface>"],"sources":["../../src/migrations/001-create-core-tables.ts"],"sourcesContent":["import type { MigrationFn } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\n\nexport const up: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_definitions\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"name\" VARCHAR NOT NULL,\n \"display_name\" VARCHAR,\n \"field_type\" VARCHAR NOT NULL,\n \"validation\" JSONB,\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"description\" TEXT,\n \"required\" BOOLEAN DEFAULT false,\n \"disabled\" BOOLEAN DEFAULT false,\n \"default_value\" JSONB,\n \"
|
|
1
|
+
{"version":3,"file":"001-create-core-tables.cjs","names":["up: MigrationFn<QueryInterface>","down: MigrationFn<QueryInterface>"],"sources":["../../src/migrations/001-create-core-tables.ts"],"sourcesContent":["import type { MigrationFn } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\n\nexport const up: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_definitions\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"name\" VARCHAR NOT NULL,\n \"display_name\" VARCHAR,\n \"field_type\" VARCHAR NOT NULL,\n \"validation\" JSONB,\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"description\" TEXT,\n \"required\" BOOLEAN DEFAULT false,\n \"disabled\" BOOLEAN DEFAULT false,\n \"default_value\" JSONB,\n \"block_editing_from_u_i\" BOOLEAN NOT NULL DEFAULT false,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n \"deleted_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"id\")\n )\n `);\n\n await sequelize.query(`\n CREATE UNIQUE INDEX IF NOT EXISTS \"unique_name_model_type\"\n ON \"custom_field_definitions\" (\"model_type\", \"entity_id\", \"name\")\n `);\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_values\" (\n \"model_id\" UUID NOT NULL,\n \"custom_field_definition_id\" UUID NOT NULL\n REFERENCES \"custom_field_definitions\" (\"id\"),\n \"value\" JSONB,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n \"deleted_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"model_id\", \"custom_field_definition_id\")\n )\n `);\n\n await sequelize.query(`\n CREATE INDEX IF NOT EXISTS \"idx_custom_field_values_active_definition_id\"\n ON \"custom_field_values\" (\"custom_field_definition_id\")\n WHERE \"deleted_at\" IS NULL\n `);\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_validators\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"schema\" JSONB NOT NULL,\n \"disabled\" BOOLEAN NOT NULL DEFAULT false,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"id\")\n )\n `);\n};\n\nexport const down: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n await sequelize.query('DROP TABLE IF EXISTS \"custom_field_values\"');\n await sequelize.query('DROP TABLE IF EXISTS \"custom_field_definitions\"');\n await sequelize.query('DROP TABLE IF EXISTS \"custom_validators\"');\n};\n"],"mappings":"AAGA,MAAaA,EAAkC,MAAO,CAAE,QAAS,KAAqB,CACpF,GAAM,CAAE,aAAc,EAEtB,MAAM,EAAU,MAAM;;;;;;;;;;;;;;;;;;;;IAoBpB,CAEF,MAAM,EAAU,MAAM;;;IAGpB,CAEF,MAAM,EAAU,MAAM;;;;;;;;;;;IAWpB,CAEF,MAAM,EAAU,MAAM;;;;IAIpB,CAEF,MAAM,EAAU,MAAM;;;;;;;;;;;;IAYpB,EAGSC,EAAoC,MAAO,CAAE,QAAS,KAAqB,CACtF,GAAM,CAAE,aAAc,EACtB,MAAM,EAAU,MAAM,6CAA6C,CACnE,MAAM,EAAU,MAAM,kDAAkD,CACxE,MAAM,EAAU,MAAM,2CAA2C"}
|
|
@@ -12,7 +12,7 @@ const e=async({context:e})=>{let{sequelize:t}=e;await t.query(`
|
|
|
12
12
|
"required" BOOLEAN DEFAULT false,
|
|
13
13
|
"disabled" BOOLEAN DEFAULT false,
|
|
14
14
|
"default_value" JSONB,
|
|
15
|
-
"
|
|
15
|
+
"block_editing_from_u_i" BOOLEAN NOT NULL DEFAULT false,
|
|
16
16
|
"created_at" TIMESTAMPTZ NOT NULL,
|
|
17
17
|
"updated_at" TIMESTAMPTZ,
|
|
18
18
|
"deleted_at" TIMESTAMPTZ,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"001-create-core-tables.js","names":["up: MigrationFn<QueryInterface>","down: MigrationFn<QueryInterface>"],"sources":["../../src/migrations/001-create-core-tables.ts"],"sourcesContent":["import type { MigrationFn } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\n\nexport const up: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_definitions\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"name\" VARCHAR NOT NULL,\n \"display_name\" VARCHAR,\n \"field_type\" VARCHAR NOT NULL,\n \"validation\" JSONB,\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"description\" TEXT,\n \"required\" BOOLEAN DEFAULT false,\n \"disabled\" BOOLEAN DEFAULT false,\n \"default_value\" JSONB,\n \"
|
|
1
|
+
{"version":3,"file":"001-create-core-tables.js","names":["up: MigrationFn<QueryInterface>","down: MigrationFn<QueryInterface>"],"sources":["../../src/migrations/001-create-core-tables.ts"],"sourcesContent":["import type { MigrationFn } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\n\nexport const up: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_definitions\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"name\" VARCHAR NOT NULL,\n \"display_name\" VARCHAR,\n \"field_type\" VARCHAR NOT NULL,\n \"validation\" JSONB,\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"description\" TEXT,\n \"required\" BOOLEAN DEFAULT false,\n \"disabled\" BOOLEAN DEFAULT false,\n \"default_value\" JSONB,\n \"block_editing_from_u_i\" BOOLEAN NOT NULL DEFAULT false,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n \"deleted_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"id\")\n )\n `);\n\n await sequelize.query(`\n CREATE UNIQUE INDEX IF NOT EXISTS \"unique_name_model_type\"\n ON \"custom_field_definitions\" (\"model_type\", \"entity_id\", \"name\")\n `);\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_field_values\" (\n \"model_id\" UUID NOT NULL,\n \"custom_field_definition_id\" UUID NOT NULL\n REFERENCES \"custom_field_definitions\" (\"id\"),\n \"value\" JSONB,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n \"deleted_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"model_id\", \"custom_field_definition_id\")\n )\n `);\n\n await sequelize.query(`\n CREATE INDEX IF NOT EXISTS \"idx_custom_field_values_active_definition_id\"\n ON \"custom_field_values\" (\"custom_field_definition_id\")\n WHERE \"deleted_at\" IS NULL\n `);\n\n await sequelize.query(`\n CREATE TABLE IF NOT EXISTS \"custom_validators\" (\n \"id\" UUID NOT NULL DEFAULT gen_random_uuid(),\n \"entity_id\" UUID NOT NULL,\n \"entity_type\" VARCHAR NOT NULL,\n \"model_type\" VARCHAR NOT NULL,\n \"schema\" JSONB NOT NULL,\n \"disabled\" BOOLEAN NOT NULL DEFAULT false,\n \"created_at\" TIMESTAMPTZ NOT NULL,\n \"updated_at\" TIMESTAMPTZ,\n PRIMARY KEY (\"id\")\n )\n `);\n};\n\nexport const down: MigrationFn<QueryInterface> = async ({ context: queryInterface }) => {\n const { sequelize } = queryInterface;\n await sequelize.query('DROP TABLE IF EXISTS \"custom_field_values\"');\n await sequelize.query('DROP TABLE IF EXISTS \"custom_field_definitions\"');\n await sequelize.query('DROP TABLE IF EXISTS \"custom_validators\"');\n};\n"],"mappings":"AAGA,MAAaA,EAAkC,MAAO,CAAE,QAAS,KAAqB,CACpF,GAAM,CAAE,aAAc,EAEtB,MAAM,EAAU,MAAM;;;;;;;;;;;;;;;;;;;;IAoBpB,CAEF,MAAM,EAAU,MAAM;;;IAGpB,CAEF,MAAM,EAAU,MAAM;;;;;;;;;;;IAWpB,CAEF,MAAM,EAAU,MAAM;;;;IAIpB,CAEF,MAAM,EAAU,MAAM;;;;;;;;;;;;IAYpB,EAGSC,EAAoC,MAAO,CAAE,QAAS,KAAqB,CACtF,GAAM,CAAE,aAAc,EACtB,MAAM,EAAU,MAAM,6CAA6C,CACnE,MAAM,EAAU,MAAM,kDAAkD,CACxE,MAAM,EAAU,MAAM,2CAA2C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`../utils/logger/index.cjs`),t=require(`./001-create-core-tables.cjs`),n=require(`./002-create-custom-field-entries.cjs`),r=require(`./003-create-custom-field-model-type-map.cjs`),{Umzug:i,SequelizeStorage:a}=require(`umzug`),o=
|
|
1
|
+
const e=require(`../utils/logger/index.cjs`),t=require(`./001-create-core-tables.cjs`),n=require(`./002-create-custom-field-entries.cjs`),r=require(`./003-create-custom-field-model-type-map.cjs`),{Umzug:i,SequelizeStorage:a}=require(`umzug`),o=e=>{let{useCustomFieldsEntries:i=!1,useModelTypeMapping:a=!1}=e;return[{name:`001-create-core-tables`,up:t.up,down:t.down},...i?[{name:`002-create-custom-field-entries`,up:n.up,down:n.down}]:[],...a?[{name:`003-create-custom-field-model-type-map`,up:r.up,down:r.down}]:[]]},s=839274628,c=async(t,n={})=>{let r=t.getQueryInterface(),c=new a({sequelize:t,tableName:`sadot_migrations`}),l=new i({migrations:o(n),context:r,storage:c,logger:{info:t=>e.default.info(`[umzug] ${JSON.stringify(t)}`),warn:t=>e.default.warn(`[umzug] ${JSON.stringify(t)}`),error:t=>e.default.error(`[umzug] ${JSON.stringify(t)}`),debug:t=>e.default.debug(`[umzug] ${JSON.stringify(t)}`)}}),u=await l.pending();if(u.length===0){e.default.info(`[umzug] no pending migrations, skipping`);return}e.default.info(`[umzug] pending migrations detected, acquiring advisory lock`,{pending:u.map(e=>e.name)});let d=await t.transaction();try{await t.query(`SELECT pg_advisory_lock(${s})`,{transaction:d}),e.default.info(`[umzug] advisory lock acquired`),(await l.pending()).length>0?await l.up():e.default.info(`[umzug] migrations already applied by another instance, skipping`)}finally{await t.query(`SELECT pg_advisory_unlock(${s})`,{transaction:d}),await d.commit(),e.default.info(`[umzug] advisory lock released`)}};exports.runSadotMigrations=c;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["logger"],"sources":["../../src/migrations/index.ts"],"sourcesContent":["import type { InputMigrations } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport * as migration001 from './001-create-core-tables';\nimport * as migration002 from './002-create-custom-field-entries';\nimport * as migration003 from './003-create-custom-field-model-type-map';\n\n// umzug is CJS. Static ESM named imports break in vitest after vi.resetModules()\n// because Vite's SSR transform re-evaluates the module outside the inline bundle.\n// require() goes through Node's native CJS loader and is stable across resets.\n\n// eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-require-imports\nconst { Umzug, SequelizeStorage } = require('umzug') as typeof import('umzug');\n\ninterface MigratorOptions {\n useCustomFieldsEntries?: boolean;\n useModelTypeMapping?: boolean;\n}\n\nconst buildMigrationList = (options: MigratorOptions): InputMigrations<QueryInterface> => {\n const { useCustomFieldsEntries = false, useModelTypeMapping = false } = options;\n return [\n { name: '001-create-core-tables', up: migration001.up, down: migration001.down },\n ...(useCustomFieldsEntries ? [{ name: '002-create-custom-field-entries', up: migration002.up, down: migration002.down }] : []),\n ...(useModelTypeMapping ? [{ name: '003-create-custom-field-model-type-map', up: migration003.up, down: migration003.down }] : []),\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["logger"],"sources":["../../src/migrations/index.ts"],"sourcesContent":["import type { InputMigrations } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport * as migration001 from './001-create-core-tables';\nimport * as migration002 from './002-create-custom-field-entries';\nimport * as migration003 from './003-create-custom-field-model-type-map';\n\n// umzug is CJS. Static ESM named imports break in vitest after vi.resetModules()\n// because Vite's SSR transform re-evaluates the module outside the inline bundle.\n// require() goes through Node's native CJS loader and is stable across resets.\n\n// eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-require-imports\nconst { Umzug, SequelizeStorage } = require('umzug') as typeof import('umzug');\n\ninterface MigratorOptions {\n useCustomFieldsEntries?: boolean;\n useModelTypeMapping?: boolean;\n}\n\nconst buildMigrationList = (options: MigratorOptions): InputMigrations<QueryInterface> => {\n const { useCustomFieldsEntries = false, useModelTypeMapping = false } = options;\n return [\n { name: '001-create-core-tables', up: migration001.up, down: migration001.down },\n ...(useCustomFieldsEntries ? [{ name: '002-create-custom-field-entries', up: migration002.up, down: migration002.down }] : []),\n ...(useModelTypeMapping ? [{ name: '003-create-custom-field-model-type-map', up: migration003.up, down: migration003.down }] : []),\n ];\n};\n\n// Stable advisory-lock ID for sadot migrations. Chosen arbitrarily; must not\n// collide with other advisory locks in the same database.\nconst SADOT_MIGRATION_LOCK_ID = 839274628;\n\n/**\n * Runs sadot migrations via umzug. All migrations use IF NOT EXISTS / IF EXISTS,\n * so they are fully idempotent — safe to run against both fresh and existing\n * databases (including DBs previously managed by the legacy sync() path).\n *\n * A PostgreSQL advisory lock is acquired before running migrations so that when\n * multiple pods start concurrently only one of them executes the migrations.\n * The remaining pods block until the lock is released, then proceed — Umzug will\n * see the migrations have already been applied and skip them.\n */\nconst runSadotMigrations = async (sequelize: Sequelize, options: MigratorOptions = {}): Promise<void> => {\n const queryInterface = sequelize.getQueryInterface() as unknown as QueryInterface;\n const storage = new SequelizeStorage({ sequelize: sequelize as never, tableName: 'sadot_migrations' });\n\n const umzugLogger = {\n info: (msg: Record<string, unknown>) => logger.info(`[umzug] ${JSON.stringify(msg)}`),\n warn: (msg: Record<string, unknown>) => logger.warn(`[umzug] ${JSON.stringify(msg)}`),\n error: (msg: Record<string, unknown>) => logger.error(`[umzug] ${JSON.stringify(msg)}`),\n debug: (msg: Record<string, unknown>) => logger.debug(`[umzug] ${JSON.stringify(msg)}`),\n };\n\n const migrator = new Umzug<QueryInterface>({\n migrations: buildMigrationList(options),\n context: queryInterface,\n storage,\n logger: umzugLogger,\n });\n\n const pending = await migrator.pending();\n if (pending.length === 0) {\n logger.info('[umzug] no pending migrations, skipping');\n return;\n }\n\n logger.info('[umzug] pending migrations detected, acquiring advisory lock', { pending: pending.map(m => m.name) });\n\n // Use a transaction to pin lock/unlock to the same pool connection.\n // pg_advisory_lock (session-level) is used so the lock remains held while\n // migrator.up() runs its own queries on other pool connections.\n const transaction = await sequelize.transaction();\n try {\n await sequelize.query(`SELECT pg_advisory_lock(${SADOT_MIGRATION_LOCK_ID})`, { transaction });\n logger.info('[umzug] advisory lock acquired');\n\n // Re-check after acquiring the lock — another pod may have already\n // applied the migrations while we were waiting.\n const stillPending = await migrator.pending();\n if (stillPending.length > 0) {\n await migrator.up();\n } else {\n logger.info('[umzug] migrations already applied by another instance, skipping');\n }\n } finally {\n await sequelize.query(`SELECT pg_advisory_unlock(${SADOT_MIGRATION_LOCK_ID})`, { transaction });\n await transaction.commit();\n logger.info('[umzug] advisory lock released');\n }\n};\n\nexport { runSadotMigrations };\n"],"mappings":"oMAaM,CAAE,QAAO,oBAAqB,QAAQ,QAAQ,CAO9C,EAAsB,GAA8D,CACxF,GAAM,CAAE,yBAAyB,GAAO,sBAAsB,IAAU,EACxE,MAAO,CACL,CAAE,KAAM,yBAA0B,GAAA,EAAA,GAAqB,KAAA,EAAA,KAAyB,CAChF,GAAI,EAAyB,CAAC,CAAE,KAAM,kCAAmC,GAAA,EAAA,GAAqB,KAAA,EAAA,KAAyB,CAAC,CAAG,EAAE,CAC7H,GAAI,EAAsB,CAAC,CAAE,KAAM,yCAA0C,GAAA,EAAA,GAAqB,KAAA,EAAA,KAAyB,CAAC,CAAG,EAAE,CAClI,EAKG,EAA0B,UAY1B,EAAqB,MAAO,EAAsB,EAA2B,EAAE,GAAoB,CACvG,IAAM,EAAiB,EAAU,mBAAmB,CAC9C,EAAU,IAAI,EAAiB,CAAa,YAAoB,UAAW,mBAAoB,CAAC,CAShG,EAAW,IAAI,EAAsB,CACzC,WAAY,EAAmB,EAAQ,CACvC,QAAS,EACT,UACA,OAXkB,CAClB,KAAO,GAAiCA,EAAAA,QAAO,KAAK,WAAW,KAAK,UAAU,EAAI,GAAG,CACrF,KAAO,GAAiCA,EAAAA,QAAO,KAAK,WAAW,KAAK,UAAU,EAAI,GAAG,CACrF,MAAQ,GAAiCA,EAAAA,QAAO,MAAM,WAAW,KAAK,UAAU,EAAI,GAAG,CACvF,MAAQ,GAAiCA,EAAAA,QAAO,MAAM,WAAW,KAAK,UAAU,EAAI,GAAG,CACxF,CAOA,CAAC,CAEI,EAAU,MAAM,EAAS,SAAS,CACxC,GAAI,EAAQ,SAAW,EAAG,CACxB,EAAA,QAAO,KAAK,0CAA0C,CACtD,OAGF,EAAA,QAAO,KAAK,+DAAgE,CAAE,QAAS,EAAQ,IAAI,GAAK,EAAE,KAAK,CAAE,CAAC,CAKlH,IAAM,EAAc,MAAM,EAAU,aAAa,CACjD,GAAI,CACF,MAAM,EAAU,MAAM,2BAA2B,EAAwB,GAAI,CAAE,cAAa,CAAC,CAC7F,EAAA,QAAO,KAAK,iCAAiC,EAIxB,MAAM,EAAS,SAAS,EAC5B,OAAS,EACxB,MAAM,EAAS,IAAI,CAEnB,EAAA,QAAO,KAAK,mEAAmE,QAEzE,CACR,MAAM,EAAU,MAAM,6BAA6B,EAAwB,GAAI,CAAE,cAAa,CAAC,CAC/F,MAAM,EAAY,QAAQ,CAC1B,EAAA,QAAO,KAAK,iCAAiC"}
|
package/dist/migrations/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__require as e}from"../_virtual/rolldown_runtime.js";import t from"../utils/logger/index.js";import{down as n,up as r}from"./001-create-core-tables.js";import{down as i,up as a}from"./002-create-custom-field-entries.js";import{down as o,up as s}from"./003-create-custom-field-model-type-map.js";const{Umzug:c,SequelizeStorage:l}=e(`umzug`),u=e=>{let{useCustomFieldsEntries:
|
|
1
|
+
import{__require as e}from"../_virtual/rolldown_runtime.js";import t from"../utils/logger/index.js";import{down as n,up as r}from"./001-create-core-tables.js";import{down as i,up as a}from"./002-create-custom-field-entries.js";import{down as o,up as s}from"./003-create-custom-field-model-type-map.js";const{Umzug:c,SequelizeStorage:l}=e(`umzug`),u=e=>{let{useCustomFieldsEntries:t=!1,useModelTypeMapping:c=!1}=e;return[{name:`001-create-core-tables`,up:r,down:n},...t?[{name:`002-create-custom-field-entries`,up:a,down:i}]:[],...c?[{name:`003-create-custom-field-model-type-map`,up:s,down:o}]:[]]},d=839274628,f=async(e,n={})=>{let r=e.getQueryInterface(),i=new l({sequelize:e,tableName:`sadot_migrations`}),a=new c({migrations:u(n),context:r,storage:i,logger:{info:e=>t.info(`[umzug] ${JSON.stringify(e)}`),warn:e=>t.warn(`[umzug] ${JSON.stringify(e)}`),error:e=>t.error(`[umzug] ${JSON.stringify(e)}`),debug:e=>t.debug(`[umzug] ${JSON.stringify(e)}`)}}),o=await a.pending();if(o.length===0){t.info(`[umzug] no pending migrations, skipping`);return}t.info(`[umzug] pending migrations detected, acquiring advisory lock`,{pending:o.map(e=>e.name)});let s=await e.transaction();try{await e.query(`SELECT pg_advisory_lock(${d})`,{transaction:s}),t.info(`[umzug] advisory lock acquired`),(await a.pending()).length>0?await a.up():t.info(`[umzug] migrations already applied by another instance, skipping`)}finally{await e.query(`SELECT pg_advisory_unlock(${d})`,{transaction:s}),await s.commit(),t.info(`[umzug] advisory lock released`)}};export{f as runSadotMigrations};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["migration001.up","migration001.down","migration002.up","migration002.down","migration003.up","migration003.down","logger"],"sources":["../../src/migrations/index.ts"],"sourcesContent":["import type { InputMigrations } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport * as migration001 from './001-create-core-tables';\nimport * as migration002 from './002-create-custom-field-entries';\nimport * as migration003 from './003-create-custom-field-model-type-map';\n\n// umzug is CJS. Static ESM named imports break in vitest after vi.resetModules()\n// because Vite's SSR transform re-evaluates the module outside the inline bundle.\n// require() goes through Node's native CJS loader and is stable across resets.\n\n// eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-require-imports\nconst { Umzug, SequelizeStorage } = require('umzug') as typeof import('umzug');\n\ninterface MigratorOptions {\n useCustomFieldsEntries?: boolean;\n useModelTypeMapping?: boolean;\n}\n\nconst buildMigrationList = (options: MigratorOptions): InputMigrations<QueryInterface> => {\n const { useCustomFieldsEntries = false, useModelTypeMapping = false } = options;\n return [\n { name: '001-create-core-tables', up: migration001.up, down: migration001.down },\n ...(useCustomFieldsEntries ? [{ name: '002-create-custom-field-entries', up: migration002.up, down: migration002.down }] : []),\n ...(useModelTypeMapping ? [{ name: '003-create-custom-field-model-type-map', up: migration003.up, down: migration003.down }] : []),\n
|
|
1
|
+
{"version":3,"file":"index.js","names":["migration001.up","migration001.down","migration002.up","migration002.down","migration003.up","migration003.down","logger"],"sources":["../../src/migrations/index.ts"],"sourcesContent":["import type { InputMigrations } from 'umzug';\nimport type { QueryInterface } from 'sequelize';\nimport type { Sequelize } from 'sequelize-typescript';\nimport logger from '../utils/logger';\nimport * as migration001 from './001-create-core-tables';\nimport * as migration002 from './002-create-custom-field-entries';\nimport * as migration003 from './003-create-custom-field-model-type-map';\n\n// umzug is CJS. Static ESM named imports break in vitest after vi.resetModules()\n// because Vite's SSR transform re-evaluates the module outside the inline bundle.\n// require() goes through Node's native CJS loader and is stable across resets.\n\n// eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-require-imports\nconst { Umzug, SequelizeStorage } = require('umzug') as typeof import('umzug');\n\ninterface MigratorOptions {\n useCustomFieldsEntries?: boolean;\n useModelTypeMapping?: boolean;\n}\n\nconst buildMigrationList = (options: MigratorOptions): InputMigrations<QueryInterface> => {\n const { useCustomFieldsEntries = false, useModelTypeMapping = false } = options;\n return [\n { name: '001-create-core-tables', up: migration001.up, down: migration001.down },\n ...(useCustomFieldsEntries ? [{ name: '002-create-custom-field-entries', up: migration002.up, down: migration002.down }] : []),\n ...(useModelTypeMapping ? [{ name: '003-create-custom-field-model-type-map', up: migration003.up, down: migration003.down }] : []),\n ];\n};\n\n// Stable advisory-lock ID for sadot migrations. Chosen arbitrarily; must not\n// collide with other advisory locks in the same database.\nconst SADOT_MIGRATION_LOCK_ID = 839274628;\n\n/**\n * Runs sadot migrations via umzug. All migrations use IF NOT EXISTS / IF EXISTS,\n * so they are fully idempotent — safe to run against both fresh and existing\n * databases (including DBs previously managed by the legacy sync() path).\n *\n * A PostgreSQL advisory lock is acquired before running migrations so that when\n * multiple pods start concurrently only one of them executes the migrations.\n * The remaining pods block until the lock is released, then proceed — Umzug will\n * see the migrations have already been applied and skip them.\n */\nconst runSadotMigrations = async (sequelize: Sequelize, options: MigratorOptions = {}): Promise<void> => {\n const queryInterface = sequelize.getQueryInterface() as unknown as QueryInterface;\n const storage = new SequelizeStorage({ sequelize: sequelize as never, tableName: 'sadot_migrations' });\n\n const umzugLogger = {\n info: (msg: Record<string, unknown>) => logger.info(`[umzug] ${JSON.stringify(msg)}`),\n warn: (msg: Record<string, unknown>) => logger.warn(`[umzug] ${JSON.stringify(msg)}`),\n error: (msg: Record<string, unknown>) => logger.error(`[umzug] ${JSON.stringify(msg)}`),\n debug: (msg: Record<string, unknown>) => logger.debug(`[umzug] ${JSON.stringify(msg)}`),\n };\n\n const migrator = new Umzug<QueryInterface>({\n migrations: buildMigrationList(options),\n context: queryInterface,\n storage,\n logger: umzugLogger,\n });\n\n const pending = await migrator.pending();\n if (pending.length === 0) {\n logger.info('[umzug] no pending migrations, skipping');\n return;\n }\n\n logger.info('[umzug] pending migrations detected, acquiring advisory lock', { pending: pending.map(m => m.name) });\n\n // Use a transaction to pin lock/unlock to the same pool connection.\n // pg_advisory_lock (session-level) is used so the lock remains held while\n // migrator.up() runs its own queries on other pool connections.\n const transaction = await sequelize.transaction();\n try {\n await sequelize.query(`SELECT pg_advisory_lock(${SADOT_MIGRATION_LOCK_ID})`, { transaction });\n logger.info('[umzug] advisory lock acquired');\n\n // Re-check after acquiring the lock — another pod may have already\n // applied the migrations while we were waiting.\n const stillPending = await migrator.pending();\n if (stillPending.length > 0) {\n await migrator.up();\n } else {\n logger.info('[umzug] migrations already applied by another instance, skipping');\n }\n } finally {\n await sequelize.query(`SELECT pg_advisory_unlock(${SADOT_MIGRATION_LOCK_ID})`, { transaction });\n await transaction.commit();\n logger.info('[umzug] advisory lock released');\n }\n};\n\nexport { runSadotMigrations };\n"],"mappings":"8SAaA,KAAM,CAAE,QAAO,oBAAA,EAA6B,QAAQ,CAO9C,EAAsB,GAA8D,CACxF,GAAM,CAAE,yBAAyB,GAAO,sBAAsB,IAAU,EACxE,MAAO,CACL,CAAE,KAAM,yBAA8BA,KAAuBC,OAAmB,CAChF,GAAI,EAAyB,CAAC,CAAE,KAAM,kCAAmC,GAAIC,EAAiB,KAAMC,EAAmB,CAAC,CAAG,EAAE,CAC7H,GAAI,EAAsB,CAAC,CAAE,KAAM,yCAA0C,GAAIC,EAAiB,KAAMC,EAAmB,CAAC,CAAG,EAAE,CAClI,EAKG,EAA0B,UAY1B,EAAqB,MAAO,EAAsB,EAA2B,EAAE,GAAoB,CACvG,IAAM,EAAiB,EAAU,mBAAmB,CAC9C,EAAU,IAAI,EAAiB,CAAa,YAAoB,UAAW,mBAAoB,CAAC,CAShG,EAAW,IAAI,EAAsB,CACzC,WAAY,EAAmB,EAAQ,CACvC,QAAS,EACT,UACA,OAXkB,CAClB,KAAO,GAAiCC,EAAO,KAAK,WAAW,KAAK,UAAU,EAAI,GAAG,CACrF,KAAO,GAAiCA,EAAO,KAAK,WAAW,KAAK,UAAU,EAAI,GAAG,CACrF,MAAQ,GAAiCA,EAAO,MAAM,WAAW,KAAK,UAAU,EAAI,GAAG,CACvF,MAAQ,GAAiCA,EAAO,MAAM,WAAW,KAAK,UAAU,EAAI,GAAG,CACxF,CAOA,CAAC,CAEI,EAAU,MAAM,EAAS,SAAS,CACxC,GAAI,EAAQ,SAAW,EAAG,CACxB,EAAO,KAAK,0CAA0C,CACtD,OAGF,EAAO,KAAK,+DAAgE,CAAE,QAAS,EAAQ,IAAI,GAAK,EAAE,KAAK,CAAE,CAAC,CAKlH,IAAM,EAAc,MAAM,EAAU,aAAa,CACjD,GAAI,CACF,MAAM,EAAU,MAAM,2BAA2B,EAAwB,GAAI,CAAE,cAAa,CAAC,CAC7F,EAAO,KAAK,iCAAiC,EAIxB,MAAM,EAAS,SAAS,EAC5B,OAAS,EACxB,MAAM,EAAS,IAAI,CAEnB,EAAO,KAAK,mEAAmE,QAEzE,CACR,MAAM,EAAU,MAAM,6BAA6B,EAAwB,GAAI,CAAE,cAAa,CAAC,CAC/F,MAAM,EAAY,QAAQ,CAC1B,EAAO,KAAK,iCAAiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/sadot",
|
|
3
|
-
"version": "1.6.0-alpha.
|
|
3
|
+
"version": "1.6.0-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"npm-watch": "^0.11.0",
|
|
55
55
|
"supertest": "^7.0.0",
|
|
56
56
|
"@autofleet/errors": "^3.1.53",
|
|
57
|
+
"@autofleet/node-common": "^4.3.13",
|
|
57
58
|
"@autofleet/zehut": "^4.12.8",
|
|
58
|
-
"@autofleet/logger": "^4.5.1"
|
|
59
|
-
"@autofleet/node-common": "^4.3.13"
|
|
59
|
+
"@autofleet/logger": "^4.5.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"@autofleet/errors": "^3",
|