drizzle-orm 1.0.0-beta.1-8c98244 → 1.0.0-beta.1-02522e1
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/cockroach-core/query-builders/count.cjs.map +1 -1
- package/cockroach-core/query-builders/count.d.cts +3 -2
- package/cockroach-core/query-builders/count.d.ts +3 -2
- package/cockroach-core/query-builders/count.js.map +1 -1
- package/cockroach-core/schema.cjs +8 -1
- package/cockroach-core/schema.cjs.map +1 -1
- package/cockroach-core/schema.js +9 -2
- package/cockroach-core/schema.js.map +1 -1
- package/cockroach-core/table.cjs +23 -2
- package/cockroach-core/table.cjs.map +1 -1
- package/cockroach-core/table.d.cts +4 -1
- package/cockroach-core/table.d.ts +4 -1
- package/cockroach-core/table.js +23 -2
- package/cockroach-core/table.js.map +1 -1
- package/durable-sqlite/migrator.cjs +10 -7
- package/durable-sqlite/migrator.cjs.map +1 -1
- package/durable-sqlite/migrator.d.cts +0 -8
- package/durable-sqlite/migrator.d.ts +0 -8
- package/durable-sqlite/migrator.js +10 -7
- package/durable-sqlite/migrator.js.map +1 -1
- package/expo-sqlite/migrator.cjs +10 -7
- package/expo-sqlite/migrator.cjs.map +1 -1
- package/expo-sqlite/migrator.d.cts +0 -8
- package/expo-sqlite/migrator.d.ts +0 -8
- package/expo-sqlite/migrator.js +10 -7
- package/expo-sqlite/migrator.js.map +1 -1
- package/gel-core/query-builders/count.cjs.map +1 -1
- package/gel-core/query-builders/count.d.cts +3 -2
- package/gel-core/query-builders/count.d.ts +3 -2
- package/gel-core/query-builders/count.js.map +1 -1
- package/migrator.cjs +42 -5
- package/migrator.cjs.map +1 -1
- package/migrator.d.cts +1 -0
- package/migrator.d.ts +1 -0
- package/migrator.js +42 -6
- package/migrator.js.map +1 -1
- package/mssql-core/dialect.cjs +2 -2
- package/mssql-core/dialect.cjs.map +1 -1
- package/mssql-core/dialect.js +2 -2
- package/mssql-core/dialect.js.map +1 -1
- package/op-sqlite/migrator.cjs +10 -7
- package/op-sqlite/migrator.cjs.map +1 -1
- package/op-sqlite/migrator.d.cts +0 -16
- package/op-sqlite/migrator.d.ts +0 -16
- package/op-sqlite/migrator.js +10 -7
- package/op-sqlite/migrator.js.map +1 -1
- package/package.json +97 -97
- package/pg-core/query-builders/count.cjs.map +1 -1
- package/pg-core/query-builders/count.d.cts +3 -2
- package/pg-core/query-builders/count.d.ts +3 -2
- package/pg-core/query-builders/count.js.map +1 -1
- package/pg-core/schema.cjs +7 -0
- package/pg-core/schema.cjs.map +1 -1
- package/pg-core/schema.js +8 -1
- package/pg-core/schema.js.map +1 -1
- package/pg-core/table.cjs +16 -8
- package/pg-core/table.cjs.map +1 -1
- package/pg-core/table.d.cts +5 -4
- package/pg-core/table.d.ts +5 -4
- package/pg-core/table.js +16 -8
- package/pg-core/table.js.map +1 -1
- package/relations.cjs +2 -0
- package/relations.cjs.map +1 -1
- package/relations.d.cts +3 -3
- package/relations.d.ts +3 -3
- package/relations.js +3 -1
- package/relations.js.map +1 -1
- package/sql/sql.cjs +0 -6
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.d.cts +2 -2
- package/sql/sql.d.ts +2 -2
- package/sql/sql.js +0 -6
- package/sql/sql.js.map +1 -1
- package/table.cjs +0 -1
- package/table.cjs.map +1 -1
- package/table.d.cts +2 -3
- package/table.d.ts +2 -3
- package/table.js +0 -1
- package/table.js.map +1 -1
- package/version.cjs +2 -2
- package/version.cjs.map +1 -1
- package/version.d.cts +2 -2
- package/version.d.ts +2 -2
- package/version.js +2 -2
- package/version.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport type
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport { formatToMillis, type MigrationMeta } from '~/migrator.ts';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n\tmigrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tconst sortedMigrations = Object.keys(migrations).sort();\n\n\tfor (const key of sortedMigrations) {\n\t\tconst query = migrations[key];\n\t\tif (!query) {\n\t\t\tthrow new Error(`Missing migration: ${key}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tconst migrationDate = formatToMillis(key.slice(0, 14));\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: true,\n\t\t\t\tfolderMillis: migrationDate,\n\t\t\t\thash: '',\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`Failed to parse migration: ${key}`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport async function migrate<\n\tTSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations = EmptyRelations,\n>(\n\tdb: ExpoSQLiteDatabase<TSchema, TRelations>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = await readMigrationFiles(config);\n\treturn db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error };\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any, any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t};\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState };\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload };\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t};\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' });\n\t\tmigrate(db, migrations as any).then(() => {\n\t\t\tdispatch({ type: 'migrated', payload: true });\n\t\t}).catch((error) => {\n\t\t\tdispatch({ type: 'error', payload: error as Error });\n\t\t});\n\t}, []);\n\n\treturn state;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAsC;AACtC,sBAAmD;AAQnD,eAAe,mBAAmB,EAAE,WAAW,GAA8C;AAC5F,QAAM,mBAAoC,CAAC;AAE3C,QAAM,mBAAmB,OAAO,KAAK,UAAU,EAAE,KAAK;AAEtD,aAAW,OAAO,kBAAkB;AACnC,UAAM,QAAQ,WAAW,GAAG;AAC5B,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,sBAAsB,GAAG,EAAE;AAAA,IAC5C;AAEA,QAAI;AACH,YAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAClE,eAAO;AAAA,MACR,CAAC;AAED,YAAM,oBAAgB,gCAAe,IAAI,MAAM,GAAG,EAAE,CAAC;AAErD,uBAAiB,KAAK;AAAA,QACrB,KAAK;AAAA,QACL,KAAK;AAAA,QACL,cAAc;AAAA,QACd,MAAM;AAAA,MACP,CAAC;AAAA,IACF,QAAQ;AACP,YAAM,IAAI,MAAM,8BAA8B,GAAG,EAAE;AAAA,IACpD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,eAAsB,QAIrB,IACA,QACC;AACD,QAAM,aAAa,MAAM,mBAAmB,MAAM;AAClD,SAAO,GAAG,QAAQ,QAAQ,YAAY,GAAG,OAAO;AACjD;AAYO,MAAM,gBAAgB,CAAC,IAAkC,eAKnD;AACZ,QAAM,eAAsB;AAAA,IAC3B,SAAS;AAAA,IACT,OAAO;AAAA,EACR;AAEA,QAAM,eAAe,CAACA,QAAc,WAA0B;AAC7D,YAAQ,OAAO,MAAM;AAAA,MACpB,KAAK,aAAa;AACjB,eAAO,EAAE,GAAG,aAAa;AAAA,MAC1B;AAAA,MACA,KAAK,YAAY;AAChB,eAAO,EAAE,GAAG,cAAc,SAAS,OAAO,QAAQ;AAAA,MACnD;AAAA,MACA,KAAK,SAAS;AACb,eAAO,EAAE,GAAG,cAAc,OAAO,OAAO,QAAQ;AAAA,MACjD;AAAA,MACA,SAAS;AACR,eAAOA;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAEA,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAW,cAAc,YAAY;AAE/D,8BAAU,MAAM;AACf,aAAS,EAAE,MAAM,YAAY,CAAC;AAC9B,YAAQ,IAAI,UAAiB,EAAE,KAAK,MAAM;AACzC,eAAS,EAAE,MAAM,YAAY,SAAS,KAAK,CAAC;AAAA,IAC7C,CAAC,EAAE,MAAM,CAAC,UAAU;AACnB,eAAS,EAAE,MAAM,SAAS,SAAS,MAAe,CAAC;AAAA,IACpD,CAAC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACR;","names":["state"]}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import type { AnyRelations, EmptyRelations } from "../relations.cjs";
|
|
2
2
|
import type { ExpoSQLiteDatabase } from "./driver.cjs";
|
|
3
3
|
interface MigrationConfig {
|
|
4
|
-
journal: {
|
|
5
|
-
entries: {
|
|
6
|
-
idx: number;
|
|
7
|
-
when: number;
|
|
8
|
-
tag: string;
|
|
9
|
-
breakpoints: boolean;
|
|
10
|
-
}[];
|
|
11
|
-
};
|
|
12
4
|
migrations: Record<string, string>;
|
|
13
5
|
}
|
|
14
6
|
export declare function migrate<TSchema extends Record<string, unknown>, TRelations extends AnyRelations = EmptyRelations>(db: ExpoSQLiteDatabase<TSchema, TRelations>, config: MigrationConfig): Promise<void>;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import type { AnyRelations, EmptyRelations } from "../relations.js";
|
|
2
2
|
import type { ExpoSQLiteDatabase } from "./driver.js";
|
|
3
3
|
interface MigrationConfig {
|
|
4
|
-
journal: {
|
|
5
|
-
entries: {
|
|
6
|
-
idx: number;
|
|
7
|
-
when: number;
|
|
8
|
-
tag: string;
|
|
9
|
-
breakpoints: boolean;
|
|
10
|
-
}[];
|
|
11
|
-
};
|
|
12
4
|
migrations: Record<string, string>;
|
|
13
5
|
}
|
|
14
6
|
export declare function migrate<TSchema extends Record<string, unknown>, TRelations extends AnyRelations = EmptyRelations>(db: ExpoSQLiteDatabase<TSchema, TRelations>, config: MigrationConfig): Promise<void>;
|
package/expo-sqlite/migrator.js
CHANGED
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import { useEffect, useReducer } from "react";
|
|
2
|
-
|
|
2
|
+
import { formatToMillis } from "../migrator.js";
|
|
3
|
+
async function readMigrationFiles({ migrations }) {
|
|
3
4
|
const migrationQueries = [];
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const sortedMigrations = Object.keys(migrations).sort();
|
|
6
|
+
for (const key of sortedMigrations) {
|
|
7
|
+
const query = migrations[key];
|
|
6
8
|
if (!query) {
|
|
7
|
-
throw new Error(`Missing migration: ${
|
|
9
|
+
throw new Error(`Missing migration: ${key}`);
|
|
8
10
|
}
|
|
9
11
|
try {
|
|
10
12
|
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
11
13
|
return it;
|
|
12
14
|
});
|
|
15
|
+
const migrationDate = formatToMillis(key.slice(0, 14));
|
|
13
16
|
migrationQueries.push({
|
|
14
17
|
sql: result,
|
|
15
|
-
bps:
|
|
16
|
-
folderMillis:
|
|
18
|
+
bps: true,
|
|
19
|
+
folderMillis: migrationDate,
|
|
17
20
|
hash: ""
|
|
18
21
|
});
|
|
19
22
|
} catch {
|
|
20
|
-
throw new Error(`Failed to parse migration: ${
|
|
23
|
+
throw new Error(`Failed to parse migration: ${key}`);
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
return migrationQueries;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport type
|
|
1
|
+
{"version":3,"sources":["../../src/expo-sqlite/migrator.ts"],"sourcesContent":["import { useEffect, useReducer } from 'react';\nimport { formatToMillis, type MigrationMeta } from '~/migrator.ts';\nimport type { AnyRelations, EmptyRelations } from '~/relations.ts';\nimport type { ExpoSQLiteDatabase } from './driver.ts';\n\ninterface MigrationConfig {\n\tmigrations: Record<string, string>;\n}\n\nasync function readMigrationFiles({ migrations }: MigrationConfig): Promise<MigrationMeta[]> {\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tconst sortedMigrations = Object.keys(migrations).sort();\n\n\tfor (const key of sortedMigrations) {\n\t\tconst query = migrations[key];\n\t\tif (!query) {\n\t\t\tthrow new Error(`Missing migration: ${key}`);\n\t\t}\n\n\t\ttry {\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tconst migrationDate = formatToMillis(key.slice(0, 14));\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: true,\n\t\t\t\tfolderMillis: migrationDate,\n\t\t\t\thash: '',\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`Failed to parse migration: ${key}`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport async function migrate<\n\tTSchema extends Record<string, unknown>,\n\tTRelations extends AnyRelations = EmptyRelations,\n>(\n\tdb: ExpoSQLiteDatabase<TSchema, TRelations>,\n\tconfig: MigrationConfig,\n) {\n\tconst migrations = await readMigrationFiles(config);\n\treturn db.dialect.migrate(migrations, db.session);\n}\n\ninterface State {\n\tsuccess: boolean;\n\terror?: Error;\n}\n\ntype Action =\n\t| { type: 'migrating' }\n\t| { type: 'migrated'; payload: true }\n\t| { type: 'error'; payload: Error };\n\nexport const useMigrations = (db: ExpoSQLiteDatabase<any, any>, migrations: {\n\tjournal: {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\tmigrations: Record<string, string>;\n}): State => {\n\tconst initialState: State = {\n\t\tsuccess: false,\n\t\terror: undefined,\n\t};\n\n\tconst fetchReducer = (state: State, action: Action): State => {\n\t\tswitch (action.type) {\n\t\t\tcase 'migrating': {\n\t\t\t\treturn { ...initialState };\n\t\t\t}\n\t\t\tcase 'migrated': {\n\t\t\t\treturn { ...initialState, success: action.payload };\n\t\t\t}\n\t\t\tcase 'error': {\n\t\t\t\treturn { ...initialState, error: action.payload };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn state;\n\t\t\t}\n\t\t}\n\t};\n\n\tconst [state, dispatch] = useReducer(fetchReducer, initialState);\n\n\tuseEffect(() => {\n\t\tdispatch({ type: 'migrating' });\n\t\tmigrate(db, migrations as any).then(() => {\n\t\t\tdispatch({ type: 'migrated', payload: true });\n\t\t}).catch((error) => {\n\t\t\tdispatch({ type: 'error', payload: error as Error });\n\t\t});\n\t}, []);\n\n\treturn state;\n};\n"],"mappings":"AAAA,SAAS,WAAW,kBAAkB;AACtC,SAAS,sBAA0C;AAQnD,eAAe,mBAAmB,EAAE,WAAW,GAA8C;AAC5F,QAAM,mBAAoC,CAAC;AAE3C,QAAM,mBAAmB,OAAO,KAAK,UAAU,EAAE,KAAK;AAEtD,aAAW,OAAO,kBAAkB;AACnC,UAAM,QAAQ,WAAW,GAAG;AAC5B,QAAI,CAAC,OAAO;AACX,YAAM,IAAI,MAAM,sBAAsB,GAAG,EAAE;AAAA,IAC5C;AAEA,QAAI;AACH,YAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAClE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ACR;","names":["state"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/gel-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { GelSession } from '../session.ts';\nimport type { GelTable } from '../table.ts';\n\nexport class GelCountBuilder<\n\tTSession extends GelSession<any, any, any>,\n> extends SQL<number> implements Promise<number>, SQLWrapper {\n\tprivate sql: SQL<number>;\n\n\tstatic override readonly [entityKind]: string = 'GelCountBuilder';\n\t[Symbol.toStringTag] = 'GelCountBuilder';\n\n\tprivate session: TSession;\n\n\tprivate static buildEmbeddedCount(\n\t\tsource: GelTable | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`(select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters})`;\n\t}\n\n\tprivate static buildCount(\n\t\tsource: GelTable | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`select count(*) as count from ${source}${sql.raw(' where ').if(filters)}${filters};`;\n\t}\n\n\tconstructor(\n\t\treadonly params: {\n\t\t\tsource: GelTable | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tsession: TSession;\n\t\t},\n\t) {\n\t\tsuper(GelCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);\n\n\t\tthis.mapWith(Number);\n\n\t\tthis.session = params.session;\n\n\t\tthis.sql = GelCountBuilder.buildCount(\n\t\t\tparams.source,\n\t\t\tparams.filters,\n\t\t);\n\t}\n\n\tthen<TResult1 = number, TResult2 = never>(\n\t\tonfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\treturn Promise.resolve(this.session.count(this.sql))\n\t\t\t.then(\n\t\t\t\tonfulfilled,\n\t\t\t\tonrejected,\n\t\t\t);\n\t}\n\n\tcatch(\n\t\tonRejected?: ((reason: any) => any) | null | undefined,\n\t): Promise<number> {\n\t\treturn this.then(undefined, onRejected);\n\t}\n\n\tfinally(onFinally?: (() => void) | null | undefined): Promise<number> {\n\t\treturn this.then(\n\t\t\t(value) => {\n\t\t\t\tonFinally?.();\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tonFinally?.();\n\t\t\t\tthrow reason;\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,iBAA0C;
|
|
1
|
+
{"version":3,"sources":["../../../src/gel-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { GelSession } from '../session.ts';\nimport type { GelTable } from '../table.ts';\nimport type { GelViewBase } from '../view-base.ts';\n\nexport class GelCountBuilder<\n\tTSession extends GelSession<any, any, any>,\n> extends SQL<number> implements Promise<number>, SQLWrapper {\n\tprivate sql: SQL<number>;\n\n\tstatic override readonly [entityKind]: string = 'GelCountBuilder';\n\t[Symbol.toStringTag] = 'GelCountBuilder';\n\n\tprivate session: TSession;\n\n\tprivate static buildEmbeddedCount(\n\t\tsource: GelTable | GelViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`(select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters})`;\n\t}\n\n\tprivate static buildCount(\n\t\tsource: GelTable | GelViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`select count(*) as count from ${source}${sql.raw(' where ').if(filters)}${filters};`;\n\t}\n\n\tconstructor(\n\t\treadonly params: {\n\t\t\tsource: GelTable | GelViewBase | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tsession: TSession;\n\t\t},\n\t) {\n\t\tsuper(GelCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);\n\n\t\tthis.mapWith(Number);\n\n\t\tthis.session = params.session;\n\n\t\tthis.sql = GelCountBuilder.buildCount(\n\t\t\tparams.source,\n\t\t\tparams.filters,\n\t\t);\n\t}\n\n\tthen<TResult1 = number, TResult2 = never>(\n\t\tonfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\treturn Promise.resolve(this.session.count(this.sql))\n\t\t\t.then(\n\t\t\t\tonfulfilled,\n\t\t\t\tonrejected,\n\t\t\t);\n\t}\n\n\tcatch(\n\t\tonRejected?: ((reason: any) => any) | null | undefined,\n\t): Promise<number> {\n\t\treturn this.then(undefined, onRejected);\n\t}\n\n\tfinally(onFinally?: (() => void) | null | undefined): Promise<number> {\n\t\treturn this.then(\n\t\t\t(value) => {\n\t\t\t\tonFinally?.();\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tonFinally?.();\n\t\t\t\tthrow reason;\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAC3B,iBAA0C;AAKnC,MAAM,wBAEH,eAAmD;AAAA,EAsB5D,YACU,QAKR;AACD,UAAM,gBAAgB,mBAAmB,OAAO,QAAQ,OAAO,OAAO,EAAE,WAAW;AAN1E;AAQT,SAAK,QAAQ,MAAM;AAEnB,SAAK,UAAU,OAAO;AAEtB,SAAK,MAAM,gBAAgB;AAAA,MAC1B,OAAO;AAAA,MACP,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EAtCQ;AAAA,EAER,QAA0B,wBAAU,IAAY;AAAA,EAChD,CAAC,OAAO,WAAW,IAAI;AAAA,EAEf;AAAA,EAER,OAAe,mBACd,QACA,SACc;AACd,WAAO,uCAAoC,MAAM,GAAG,eAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7F;AAAA,EAEA,OAAe,WACd,QACA,SACc;AACd,WAAO,+CAA4C,MAAM,GAAG,eAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EACrG;AAAA,EAqBA,KACC,aACA,YAC+B;AAC/B,WAAO,QAAQ,QAAQ,KAAK,QAAQ,MAAM,KAAK,GAAG,CAAC,EACjD;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACF;AAAA,EAEA,MACC,YACkB;AAClB,WAAO,KAAK,KAAK,QAAW,UAAU;AAAA,EACvC;AAAA,EAEA,QAAQ,WAA8D;AACrE,WAAO,KAAK;AAAA,MACX,CAAC,UAAU;AACV,oBAAY;AACZ,eAAO;AAAA,MACR;AAAA,MACA,CAAC,WAAW;AACX,oBAAY;AACZ,cAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
|
@@ -2,9 +2,10 @@ import { entityKind } from "../../entity.cjs";
|
|
|
2
2
|
import { SQL, type SQLWrapper } from "../../sql/sql.cjs";
|
|
3
3
|
import type { GelSession } from "../session.cjs";
|
|
4
4
|
import type { GelTable } from "../table.cjs";
|
|
5
|
+
import type { GelViewBase } from "../view-base.cjs";
|
|
5
6
|
export declare class GelCountBuilder<TSession extends GelSession<any, any, any>> extends SQL<number> implements Promise<number>, SQLWrapper {
|
|
6
7
|
readonly params: {
|
|
7
|
-
source: GelTable | SQL | SQLWrapper;
|
|
8
|
+
source: GelTable | GelViewBase | SQL | SQLWrapper;
|
|
8
9
|
filters?: SQL<unknown>;
|
|
9
10
|
session: TSession;
|
|
10
11
|
};
|
|
@@ -15,7 +16,7 @@ export declare class GelCountBuilder<TSession extends GelSession<any, any, any>>
|
|
|
15
16
|
private static buildEmbeddedCount;
|
|
16
17
|
private static buildCount;
|
|
17
18
|
constructor(params: {
|
|
18
|
-
source: GelTable | SQL | SQLWrapper;
|
|
19
|
+
source: GelTable | GelViewBase | SQL | SQLWrapper;
|
|
19
20
|
filters?: SQL<unknown>;
|
|
20
21
|
session: TSession;
|
|
21
22
|
});
|
|
@@ -2,9 +2,10 @@ import { entityKind } from "../../entity.js";
|
|
|
2
2
|
import { SQL, type SQLWrapper } from "../../sql/sql.js";
|
|
3
3
|
import type { GelSession } from "../session.js";
|
|
4
4
|
import type { GelTable } from "../table.js";
|
|
5
|
+
import type { GelViewBase } from "../view-base.js";
|
|
5
6
|
export declare class GelCountBuilder<TSession extends GelSession<any, any, any>> extends SQL<number> implements Promise<number>, SQLWrapper {
|
|
6
7
|
readonly params: {
|
|
7
|
-
source: GelTable | SQL | SQLWrapper;
|
|
8
|
+
source: GelTable | GelViewBase | SQL | SQLWrapper;
|
|
8
9
|
filters?: SQL<unknown>;
|
|
9
10
|
session: TSession;
|
|
10
11
|
};
|
|
@@ -15,7 +16,7 @@ export declare class GelCountBuilder<TSession extends GelSession<any, any, any>>
|
|
|
15
16
|
private static buildEmbeddedCount;
|
|
16
17
|
private static buildCount;
|
|
17
18
|
constructor(params: {
|
|
18
|
-
source: GelTable | SQL | SQLWrapper;
|
|
19
|
+
source: GelTable | GelViewBase | SQL | SQLWrapper;
|
|
19
20
|
filters?: SQL<unknown>;
|
|
20
21
|
session: TSession;
|
|
21
22
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/gel-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { GelSession } from '../session.ts';\nimport type { GelTable } from '../table.ts';\n\nexport class GelCountBuilder<\n\tTSession extends GelSession<any, any, any>,\n> extends SQL<number> implements Promise<number>, SQLWrapper {\n\tprivate sql: SQL<number>;\n\n\tstatic override readonly [entityKind]: string = 'GelCountBuilder';\n\t[Symbol.toStringTag] = 'GelCountBuilder';\n\n\tprivate session: TSession;\n\n\tprivate static buildEmbeddedCount(\n\t\tsource: GelTable | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`(select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters})`;\n\t}\n\n\tprivate static buildCount(\n\t\tsource: GelTable | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`select count(*) as count from ${source}${sql.raw(' where ').if(filters)}${filters};`;\n\t}\n\n\tconstructor(\n\t\treadonly params: {\n\t\t\tsource: GelTable | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tsession: TSession;\n\t\t},\n\t) {\n\t\tsuper(GelCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);\n\n\t\tthis.mapWith(Number);\n\n\t\tthis.session = params.session;\n\n\t\tthis.sql = GelCountBuilder.buildCount(\n\t\t\tparams.source,\n\t\t\tparams.filters,\n\t\t);\n\t}\n\n\tthen<TResult1 = number, TResult2 = never>(\n\t\tonfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\treturn Promise.resolve(this.session.count(this.sql))\n\t\t\t.then(\n\t\t\t\tonfulfilled,\n\t\t\t\tonrejected,\n\t\t\t);\n\t}\n\n\tcatch(\n\t\tonRejected?: ((reason: any) => any) | null | undefined,\n\t): Promise<number> {\n\t\treturn this.then(undefined, onRejected);\n\t}\n\n\tfinally(onFinally?: (() => void) | null | undefined): Promise<number> {\n\t\treturn this.then(\n\t\t\t(value) => {\n\t\t\t\tonFinally?.();\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tonFinally?.();\n\t\t\t\tthrow reason;\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,KAAK,WAA4B;
|
|
1
|
+
{"version":3,"sources":["../../../src/gel-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { GelSession } from '../session.ts';\nimport type { GelTable } from '../table.ts';\nimport type { GelViewBase } from '../view-base.ts';\n\nexport class GelCountBuilder<\n\tTSession extends GelSession<any, any, any>,\n> extends SQL<number> implements Promise<number>, SQLWrapper {\n\tprivate sql: SQL<number>;\n\n\tstatic override readonly [entityKind]: string = 'GelCountBuilder';\n\t[Symbol.toStringTag] = 'GelCountBuilder';\n\n\tprivate session: TSession;\n\n\tprivate static buildEmbeddedCount(\n\t\tsource: GelTable | GelViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`(select count(*) from ${source}${sql.raw(' where ').if(filters)}${filters})`;\n\t}\n\n\tprivate static buildCount(\n\t\tsource: GelTable | GelViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t): SQL<number> {\n\t\treturn sql<number>`select count(*) as count from ${source}${sql.raw(' where ').if(filters)}${filters};`;\n\t}\n\n\tconstructor(\n\t\treadonly params: {\n\t\t\tsource: GelTable | GelViewBase | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tsession: TSession;\n\t\t},\n\t) {\n\t\tsuper(GelCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);\n\n\t\tthis.mapWith(Number);\n\n\t\tthis.session = params.session;\n\n\t\tthis.sql = GelCountBuilder.buildCount(\n\t\t\tparams.source,\n\t\t\tparams.filters,\n\t\t);\n\t}\n\n\tthen<TResult1 = number, TResult2 = never>(\n\t\tonfulfilled?: ((value: number) => TResult1 | PromiseLike<TResult1>) | null | undefined,\n\t\tonrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined,\n\t): Promise<TResult1 | TResult2> {\n\t\treturn Promise.resolve(this.session.count(this.sql))\n\t\t\t.then(\n\t\t\t\tonfulfilled,\n\t\t\t\tonrejected,\n\t\t\t);\n\t}\n\n\tcatch(\n\t\tonRejected?: ((reason: any) => any) | null | undefined,\n\t): Promise<number> {\n\t\treturn this.then(undefined, onRejected);\n\t}\n\n\tfinally(onFinally?: (() => void) | null | undefined): Promise<number> {\n\t\treturn this.then(\n\t\t\t(value) => {\n\t\t\t\tonFinally?.();\n\t\t\t\treturn value;\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tonFinally?.();\n\t\t\t\tthrow reason;\n\t\t\t},\n\t\t);\n\t}\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAC3B,SAAS,KAAK,WAA4B;AAKnC,MAAM,wBAEH,IAAmD;AAAA,EAsB5D,YACU,QAKR;AACD,UAAM,gBAAgB,mBAAmB,OAAO,QAAQ,OAAO,OAAO,EAAE,WAAW;AAN1E;AAQT,SAAK,QAAQ,MAAM;AAEnB,SAAK,UAAU,OAAO;AAEtB,SAAK,MAAM,gBAAgB;AAAA,MAC1B,OAAO;AAAA,MACP,OAAO;AAAA,IACR;AAAA,EACD;AAAA,EAtCQ;AAAA,EAER,QAA0B,UAAU,IAAY;AAAA,EAChD,CAAC,OAAO,WAAW,IAAI;AAAA,EAEf;AAAA,EAER,OAAe,mBACd,QACA,SACc;AACd,WAAO,4BAAoC,MAAM,GAAG,IAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7F;AAAA,EAEA,OAAe,WACd,QACA,SACc;AACd,WAAO,oCAA4C,MAAM,GAAG,IAAI,IAAI,SAAS,EAAE,GAAG,OAAO,CAAC,GAAG,OAAO;AAAA,EACrG;AAAA,EAqBA,KACC,aACA,YAC+B;AAC/B,WAAO,QAAQ,QAAQ,KAAK,QAAQ,MAAM,KAAK,GAAG,CAAC,EACjD;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACF;AAAA,EAEA,MACC,YACkB;AAClB,WAAO,KAAK,KAAK,QAAW,UAAU;AAAA,EACvC;AAAA,EAEA,QAAQ,WAA8D;AACrE,WAAO,KAAK;AAAA,MACX,CAAC,UAAU;AACV,oBAAY;AACZ,eAAO;AAAA,MACR;AAAA,MACA,CAAC,WAAW;AACX,oBAAY;AACZ,cAAM;AAAA,MACP;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
|
package/migrator.cjs
CHANGED
|
@@ -28,19 +28,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var migrator_exports = {};
|
|
30
30
|
__export(migrator_exports, {
|
|
31
|
+
formatToMillis: () => formatToMillis,
|
|
31
32
|
readMigrationFiles: () => readMigrationFiles
|
|
32
33
|
});
|
|
33
34
|
module.exports = __toCommonJS(migrator_exports);
|
|
34
35
|
var import_node_crypto = __toESM(require("node:crypto"), 1);
|
|
35
36
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
36
|
-
|
|
37
|
+
var import_node_path = require("node:path");
|
|
38
|
+
function formatToMillis(dateStr) {
|
|
39
|
+
const year = parseInt(dateStr.slice(0, 4), 10);
|
|
40
|
+
const month = parseInt(dateStr.slice(4, 6), 10) - 1;
|
|
41
|
+
const day = parseInt(dateStr.slice(6, 8), 10);
|
|
42
|
+
const hour = parseInt(dateStr.slice(8, 10), 10);
|
|
43
|
+
const minute = parseInt(dateStr.slice(10, 12), 10);
|
|
44
|
+
const second = parseInt(dateStr.slice(12, 14), 10);
|
|
45
|
+
return Date.UTC(year, month, day, hour, minute, second);
|
|
46
|
+
}
|
|
47
|
+
function readMigrationFilesOLD(config) {
|
|
37
48
|
const migrationFolderTo = config.migrationsFolder;
|
|
38
49
|
const migrationQueries = [];
|
|
39
50
|
const journalPath = `${migrationFolderTo}/meta/_journal.json`;
|
|
40
|
-
|
|
41
|
-
throw new Error(`Can't find meta/_journal.json file`);
|
|
42
|
-
}
|
|
43
|
-
const journalAsString = import_node_fs.default.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
|
|
51
|
+
const journalAsString = import_node_fs.default.readFileSync(journalPath).toString();
|
|
44
52
|
const journal = JSON.parse(journalAsString);
|
|
45
53
|
for (const journalEntry of journal.entries) {
|
|
46
54
|
const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
|
|
@@ -61,8 +69,37 @@ function readMigrationFiles(config) {
|
|
|
61
69
|
}
|
|
62
70
|
return migrationQueries;
|
|
63
71
|
}
|
|
72
|
+
function readMigrationFiles(config) {
|
|
73
|
+
if (import_node_fs.default.existsSync(`${config.migrationsFolder}/meta/_journal.json`)) {
|
|
74
|
+
console.log(
|
|
75
|
+
'\nWarning: We detected that you have old drizzle-kit migration folders. We suggest to upgrade drizzle-kit and run "drizzle-kit up"\n'
|
|
76
|
+
);
|
|
77
|
+
return readMigrationFilesOLD(config);
|
|
78
|
+
}
|
|
79
|
+
const migrationFolderTo = config.migrationsFolder;
|
|
80
|
+
const migrationQueries = [];
|
|
81
|
+
const migrations = (0, import_node_fs.readdirSync)(migrationFolderTo).map((subdir) => ({ path: (0, import_node_path.join)(migrationFolderTo, subdir, "migration.sql"), name: subdir })).filter((it) => (0, import_node_fs.existsSync)(it.path));
|
|
82
|
+
migrations.sort();
|
|
83
|
+
for (const migration of migrations) {
|
|
84
|
+
const migrationPath = migration.path;
|
|
85
|
+
const migrationDate = migration.name.slice(0, 14);
|
|
86
|
+
const query = import_node_fs.default.readFileSync(migrationPath).toString();
|
|
87
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
88
|
+
return it;
|
|
89
|
+
});
|
|
90
|
+
const millis = formatToMillis(migrationDate);
|
|
91
|
+
migrationQueries.push({
|
|
92
|
+
sql: result,
|
|
93
|
+
bps: true,
|
|
94
|
+
folderMillis: millis,
|
|
95
|
+
hash: import_node_crypto.default.createHash("sha256").update(query).digest("hex")
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return migrationQueries;
|
|
99
|
+
}
|
|
64
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
101
|
0 && (module.exports = {
|
|
102
|
+
formatToMillis,
|
|
66
103
|
readMigrationFiles
|
|
67
104
|
});
|
|
68
105
|
//# sourceMappingURL=migrator.cjs.map
|
package/migrator.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrator.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\n\nexport interface KitConfig {\n\tout: string;\n\tschema: string;\n}\n\nexport interface MigrationConfig {\n\tmigrationsFolder: string;\n\tmigrationsTable?: string;\n\tmigrationsSchema?: string;\n}\n\nexport interface MigrationMeta {\n\tsql: string[];\n\tfolderMillis: number;\n\thash: string;\n\tbps: boolean;\n}\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../src/migrator.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs, { existsSync, readdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport interface KitConfig {\n\tout: string;\n\tschema: string;\n}\n\nexport interface MigrationConfig {\n\tmigrationsFolder: string;\n\tmigrationsTable?: string;\n\tmigrationsSchema?: string;\n}\n\nexport interface MigrationMeta {\n\tsql: string[];\n\tfolderMillis: number;\n\thash: string;\n\tbps: boolean;\n}\n\nexport function formatToMillis(dateStr: string): number {\n\tconst year = parseInt(dateStr.slice(0, 4), 10);\n\tconst month = parseInt(dateStr.slice(4, 6), 10) - 1;\n\tconst day = parseInt(dateStr.slice(6, 8), 10);\n\tconst hour = parseInt(dateStr.slice(8, 10), 10);\n\tconst minute = parseInt(dateStr.slice(10, 12), 10);\n\tconst second = parseInt(dateStr.slice(12, 14), 10);\n\n\treturn Date.UTC(year, month, day, hour, minute, second);\n}\n\nfunction readMigrationFilesOLD(config: MigrationConfig): MigrationMeta[] {\n\tconst migrationFolderTo = config.migrationsFolder;\n\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tconst journalPath = `${migrationFolderTo}/meta/_journal.json`;\n\n\tconst journalAsString = fs.readFileSync(journalPath).toString();\n\n\tconst journal = JSON.parse(journalAsString) as {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\n\tfor (const journalEntry of journal.entries) {\n\t\tconst migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;\n\n\t\ttry {\n\t\t\tconst query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();\n\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: journalEntry.breakpoints,\n\t\t\t\tfolderMillis: journalEntry.when,\n\t\t\t\thash: crypto.createHash('sha256').update(query).digest('hex'),\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport function readMigrationFiles(config: MigrationConfig): MigrationMeta[] {\n\tif (fs.existsSync(`${config.migrationsFolder}/meta/_journal.json`)) {\n\t\t// it means user has folders V2\n\t\t// we need to warn to up the folders version but still apply migrations\n\t\tconsole.log(\n\t\t\t'\\nWarning: We detected that you have old drizzle-kit migration folders. We suggest to upgrade drizzle-kit and run \"drizzle-kit up\"\\n',\n\t\t);\n\t\treturn readMigrationFilesOLD(config);\n\t}\n\n\tconst migrationFolderTo = config.migrationsFolder;\n\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tconst migrations = readdirSync(migrationFolderTo)\n\t\t.map((subdir) => ({ path: join(migrationFolderTo, subdir, 'migration.sql'), name: subdir }))\n\t\t.filter((it) => existsSync(it.path));\n\n\tmigrations.sort();\n\n\tfor (const migration of migrations) {\n\t\tconst migrationPath = migration.path;\n\t\tconst migrationDate = migration.name.slice(0, 14);\n\n\t\tconst query = fs.readFileSync(migrationPath).toString();\n\n\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\treturn it;\n\t\t});\n\n\t\tconst millis = formatToMillis(migrationDate);\n\n\t\tmigrationQueries.push({\n\t\t\tsql: result,\n\t\t\tbps: true,\n\t\t\tfolderMillis: millis,\n\t\t\thash: crypto.createHash('sha256').update(query).digest('hex'),\n\t\t});\n\t}\n\n\treturn migrationQueries;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAmB;AACnB,qBAA4C;AAC5C,uBAAqB;AAoBd,SAAS,eAAe,SAAyB;AACvD,QAAM,OAAO,SAAS,QAAQ,MAAM,GAAG,CAAC,GAAG,EAAE;AAC7C,QAAM,QAAQ,SAAS,QAAQ,MAAM,GAAG,CAAC,GAAG,EAAE,IAAI;AAClD,QAAM,MAAM,SAAS,QAAQ,MAAM,GAAG,CAAC,GAAG,EAAE;AAC5C,QAAM,OAAO,SAAS,QAAQ,MAAM,GAAG,EAAE,GAAG,EAAE;AAC9C,QAAM,SAAS,SAAS,QAAQ,MAAM,IAAI,EAAE,GAAG,EAAE;AACjD,QAAM,SAAS,SAAS,QAAQ,MAAM,IAAI,EAAE,GAAG,EAAE;AAEjD,SAAO,KAAK,IAAI,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM;AACvD;AAEA,SAAS,sBAAsB,QAA0C;AACxE,QAAM,oBAAoB,OAAO;AAEjC,QAAM,mBAAoC,CAAC;AAE3C,QAAM,cAAc,GAAG,iBAAiB;AAExC,QAAM,kBAAkB,eAAAA,QAAG,aAAa,WAAW,EAAE,SAAS;AAE9D,QAAM,UAAU,KAAK,MAAM,eAAe;AAI1C,aAAW,gBAAgB,QAAQ,SAAS;AAC3C,UAAM,gBAAgB,GAAG,iBAAiB,IAAI,aAAa,GAAG;AAE9D,QAAI;AACH,YAAM,QAAQ,eAAAA,QAAG,aAAa,GAAG,iBAAiB,IAAI,aAAa,G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,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA,IAC7D,CAAC;AAAA,EACF;AAEA,SAAO;AACR;","names":["fs","crypto"]}
|
package/migrator.d.cts
CHANGED
package/migrator.d.ts
CHANGED
package/migrator.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
|
|
2
|
+
import fs, { existsSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
function formatToMillis(dateStr) {
|
|
5
|
+
const year = parseInt(dateStr.slice(0, 4), 10);
|
|
6
|
+
const month = parseInt(dateStr.slice(4, 6), 10) - 1;
|
|
7
|
+
const day = parseInt(dateStr.slice(6, 8), 10);
|
|
8
|
+
const hour = parseInt(dateStr.slice(8, 10), 10);
|
|
9
|
+
const minute = parseInt(dateStr.slice(10, 12), 10);
|
|
10
|
+
const second = parseInt(dateStr.slice(12, 14), 10);
|
|
11
|
+
return Date.UTC(year, month, day, hour, minute, second);
|
|
12
|
+
}
|
|
13
|
+
function readMigrationFilesOLD(config) {
|
|
4
14
|
const migrationFolderTo = config.migrationsFolder;
|
|
5
15
|
const migrationQueries = [];
|
|
6
16
|
const journalPath = `${migrationFolderTo}/meta/_journal.json`;
|
|
7
|
-
|
|
8
|
-
throw new Error(`Can't find meta/_journal.json file`);
|
|
9
|
-
}
|
|
10
|
-
const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
|
|
17
|
+
const journalAsString = fs.readFileSync(journalPath).toString();
|
|
11
18
|
const journal = JSON.parse(journalAsString);
|
|
12
19
|
for (const journalEntry of journal.entries) {
|
|
13
20
|
const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
|
|
@@ -28,7 +35,36 @@ function readMigrationFiles(config) {
|
|
|
28
35
|
}
|
|
29
36
|
return migrationQueries;
|
|
30
37
|
}
|
|
38
|
+
function readMigrationFiles(config) {
|
|
39
|
+
if (fs.existsSync(`${config.migrationsFolder}/meta/_journal.json`)) {
|
|
40
|
+
console.log(
|
|
41
|
+
'\nWarning: We detected that you have old drizzle-kit migration folders. We suggest to upgrade drizzle-kit and run "drizzle-kit up"\n'
|
|
42
|
+
);
|
|
43
|
+
return readMigrationFilesOLD(config);
|
|
44
|
+
}
|
|
45
|
+
const migrationFolderTo = config.migrationsFolder;
|
|
46
|
+
const migrationQueries = [];
|
|
47
|
+
const migrations = readdirSync(migrationFolderTo).map((subdir) => ({ path: join(migrationFolderTo, subdir, "migration.sql"), name: subdir })).filter((it) => existsSync(it.path));
|
|
48
|
+
migrations.sort();
|
|
49
|
+
for (const migration of migrations) {
|
|
50
|
+
const migrationPath = migration.path;
|
|
51
|
+
const migrationDate = migration.name.slice(0, 14);
|
|
52
|
+
const query = fs.readFileSync(migrationPath).toString();
|
|
53
|
+
const result = query.split("--> statement-breakpoint").map((it) => {
|
|
54
|
+
return it;
|
|
55
|
+
});
|
|
56
|
+
const millis = formatToMillis(migrationDate);
|
|
57
|
+
migrationQueries.push({
|
|
58
|
+
sql: result,
|
|
59
|
+
bps: true,
|
|
60
|
+
folderMillis: millis,
|
|
61
|
+
hash: crypto.createHash("sha256").update(query).digest("hex")
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return migrationQueries;
|
|
65
|
+
}
|
|
31
66
|
export {
|
|
67
|
+
formatToMillis,
|
|
32
68
|
readMigrationFiles
|
|
33
69
|
};
|
|
34
70
|
//# sourceMappingURL=migrator.js.map
|
package/migrator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/migrator.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs from 'node:fs';\n\nexport interface KitConfig {\n\tout: string;\n\tschema: string;\n}\n\nexport interface MigrationConfig {\n\tmigrationsFolder: string;\n\tmigrationsTable?: string;\n\tmigrationsSchema?: string;\n}\n\nexport interface MigrationMeta {\n\tsql: string[];\n\tfolderMillis: number;\n\thash: string;\n\tbps: boolean;\n}\n\nexport function
|
|
1
|
+
{"version":3,"sources":["../src/migrator.ts"],"sourcesContent":["import crypto from 'node:crypto';\nimport fs, { existsSync, readdirSync } from 'node:fs';\nimport { join } from 'node:path';\n\nexport interface KitConfig {\n\tout: string;\n\tschema: string;\n}\n\nexport interface MigrationConfig {\n\tmigrationsFolder: string;\n\tmigrationsTable?: string;\n\tmigrationsSchema?: string;\n}\n\nexport interface MigrationMeta {\n\tsql: string[];\n\tfolderMillis: number;\n\thash: string;\n\tbps: boolean;\n}\n\nexport function formatToMillis(dateStr: string): number {\n\tconst year = parseInt(dateStr.slice(0, 4), 10);\n\tconst month = parseInt(dateStr.slice(4, 6), 10) - 1;\n\tconst day = parseInt(dateStr.slice(6, 8), 10);\n\tconst hour = parseInt(dateStr.slice(8, 10), 10);\n\tconst minute = parseInt(dateStr.slice(10, 12), 10);\n\tconst second = parseInt(dateStr.slice(12, 14), 10);\n\n\treturn Date.UTC(year, month, day, hour, minute, second);\n}\n\nfunction readMigrationFilesOLD(config: MigrationConfig): MigrationMeta[] {\n\tconst migrationFolderTo = config.migrationsFolder;\n\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tconst journalPath = `${migrationFolderTo}/meta/_journal.json`;\n\n\tconst journalAsString = fs.readFileSync(journalPath).toString();\n\n\tconst journal = JSON.parse(journalAsString) as {\n\t\tentries: { idx: number; when: number; tag: string; breakpoints: boolean }[];\n\t};\n\n\tfor (const journalEntry of journal.entries) {\n\t\tconst migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;\n\n\t\ttry {\n\t\t\tconst query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();\n\n\t\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\t\treturn it;\n\t\t\t});\n\n\t\t\tmigrationQueries.push({\n\t\t\t\tsql: result,\n\t\t\t\tbps: journalEntry.breakpoints,\n\t\t\t\tfolderMillis: journalEntry.when,\n\t\t\t\thash: crypto.createHash('sha256').update(query).digest('hex'),\n\t\t\t});\n\t\t} catch {\n\t\t\tthrow new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);\n\t\t}\n\t}\n\n\treturn migrationQueries;\n}\n\nexport function readMigrationFiles(config: MigrationConfig): MigrationMeta[] {\n\tif (fs.existsSync(`${config.migrationsFolder}/meta/_journal.json`)) {\n\t\t// it means user has folders V2\n\t\t// we need to warn to up the folders version but still apply migrations\n\t\tconsole.log(\n\t\t\t'\\nWarning: We detected that you have old drizzle-kit migration folders. We suggest to upgrade drizzle-kit and run \"drizzle-kit up\"\\n',\n\t\t);\n\t\treturn readMigrationFilesOLD(config);\n\t}\n\n\tconst migrationFolderTo = config.migrationsFolder;\n\n\tconst migrationQueries: MigrationMeta[] = [];\n\n\tconst migrations = readdirSync(migrationFolderTo)\n\t\t.map((subdir) => ({ path: join(migrationFolderTo, subdir, 'migration.sql'), name: subdir }))\n\t\t.filter((it) => existsSync(it.path));\n\n\tmigrations.sort();\n\n\tfor (const migration of migrations) {\n\t\tconst migrationPath = migration.path;\n\t\tconst migrationDate = migration.name.slice(0, 14);\n\n\t\tconst query = fs.readFileSync(migrationPath).toString();\n\n\t\tconst result = query.split('--> statement-breakpoint').map((it) => {\n\t\t\treturn it;\n\t\t});\n\n\t\tconst millis = formatToMillis(migrationDate);\n\n\t\tmigrationQueries.push({\n\t\t\tsql: result,\n\t\t\tbps: true,\n\t\t\tfolderMillis: millis,\n\t\t\thash: crypto.createHash('sha256').update(query).digest('hex'),\n\t\t});\n\t}\n\n\treturn migrationQueries;\n}\n"],"mappings":"AAAA,OAAO,YAAY;AACnB,OAAO,MAAM,YAAY,mBAAmB;AAC5C,SAAS,YAAY;AAoBd,SAAS,eAAe,SAAyB;AACvD,QAAM,OAAO,SAAS,QAAQ,MAAM,GAAG,CAAC,GAAG,EAAE;AAC7C,QAAM,QAAQ,SAAS,QAAQ,MAAM,GAAG,CAAC,GAAG,EAAE,IAAI;AAClD,QAAM,MAAM,SAAS,QAA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oBAAoB,OAAO;AAEjC,QAAM,mBAAoC,CAAC;AAE3C,QAAM,aAAa,YAAY,iBAAiB,EAC9C,IAAI,CAAC,YAAY,EAAE,MAAM,KAAK,mBAAmB,QAAQ,eAAe,GAAG,MAAM,OAAO,EAAE,EAC1F,OAAO,CAAC,OAAO,WAAW,GAAG,IAAI,CAAC;AAEpC,aAAW,KAAK;AAEhB,aAAW,aAAa,YAAY;AACnC,UAAM,gBAAgB,UAAU;AAChC,UAAM,gBAAgB,UAAU,KAAK,MAAM,GAAG,EAAE;AAEhD,UAAM,QAAQ,GAAG,aAAa,aAAa,EAAE,SAAS;AAEtD,UAAM,SAAS,MAAM,MAAM,0BAA0B,EAAE,IAAI,CAAC,OAAO;AAClE,aAAO;AAAA,IACR,CAAC;AAED,UAAM,SAAS,eAAe,aAAa;AAE3C,qBAAiB,KAAK;AAAA,MACrB,KAAK;AAAA,MACL,KAAK;AAAA,MACL,cAAc;AAAA,MACd,MAAM,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA,IAC7D,CAAC;AAAA,EACF;AAEA,SAAO;AACR;","names":[]}
|
package/mssql-core/dialect.cjs
CHANGED
|
@@ -73,10 +73,10 @@ class MsSqlDialect {
|
|
|
73
73
|
`;
|
|
74
74
|
await session.execute(migrationSchemaCreate);
|
|
75
75
|
await session.execute(migrationTableCreate);
|
|
76
|
-
const dbMigrations = await session.
|
|
76
|
+
const dbMigrations = await session.execute(
|
|
77
77
|
import_sql.sql`select id, hash, created_at from ${import_sql.sql.identifier(migrationsSchema)}.${import_sql.sql.identifier(migrationsTable)} order by created_at desc offset 0 rows fetch next 1 rows only`
|
|
78
78
|
);
|
|
79
|
-
const lastDbMigration = dbMigrations[0];
|
|
79
|
+
const lastDbMigration = dbMigrations.recordset[0];
|
|
80
80
|
await session.transaction(async (tx) => {
|
|
81
81
|
for (const migration of migrations) {
|
|
82
82
|
if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) {
|