bun-query-builder 0.1.37 → 0.1.39
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/actions/introspect-db.d.ts +10 -0
- package/dist/bin/cli.js +619 -77
- package/dist/drivers/mysql.d.ts +7 -1
- package/dist/drivers/postgres.d.ts +7 -1
- package/dist/drivers/sqlite.d.ts +7 -1
- package/dist/migrations.d.ts +84 -10
- package/dist/src/index.js +621 -76
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
package/dist/drivers/mysql.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnPlan, IndexPlan, TablePlan } from '../migrations';
|
|
1
|
+
import type { ColumnPlan, IndexPlan, RebuildTableSpec, TablePlan } from '../migrations';
|
|
2
2
|
export declare interface DialectDriver {
|
|
3
3
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
4
4
|
createTable: (table: TablePlan) => string
|
|
@@ -6,6 +6,9 @@ export declare interface DialectDriver {
|
|
|
6
6
|
addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string) => string
|
|
7
7
|
addColumn: (tableName: string, column: ColumnPlan) => string
|
|
8
8
|
modifyColumn: (tableName: string, column: ColumnPlan) => string
|
|
9
|
+
renameColumn: (tableName: string, from: string, to: string) => string
|
|
10
|
+
renameTable: (from: string, to: string) => string
|
|
11
|
+
rebuildTable: (spec: RebuildTableSpec) => string
|
|
9
12
|
dropTable: (tableName: string) => string
|
|
10
13
|
dropColumn: (tableName: string, columnName: string) => string
|
|
11
14
|
dropIndex: (tableName: string, indexName: string) => string
|
|
@@ -21,6 +24,9 @@ export declare class MySQLDriver implements DialectDriver {
|
|
|
21
24
|
addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string): string;
|
|
22
25
|
addColumn(tableName: string, column: ColumnPlan): string;
|
|
23
26
|
modifyColumn(tableName: string, column: ColumnPlan): string;
|
|
27
|
+
renameColumn(tableName: string, from: string, to: string): string;
|
|
28
|
+
renameTable(from: string, to: string): string;
|
|
29
|
+
rebuildTable(): string;
|
|
24
30
|
dropTable(tableName: string): string;
|
|
25
31
|
dropColumn(tableName: string, columnName: string): string;
|
|
26
32
|
dropIndex(tableName: string, indexName: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnPlan, IndexPlan, TablePlan } from '../migrations';
|
|
1
|
+
import type { ColumnPlan, IndexPlan, RebuildTableSpec, TablePlan } from '../migrations';
|
|
2
2
|
export declare interface DialectDriver {
|
|
3
3
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
4
4
|
createTable: (table: TablePlan) => string
|
|
@@ -6,6 +6,9 @@ export declare interface DialectDriver {
|
|
|
6
6
|
addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string) => string
|
|
7
7
|
addColumn: (tableName: string, column: ColumnPlan) => string
|
|
8
8
|
modifyColumn: (tableName: string, column: ColumnPlan) => string
|
|
9
|
+
renameColumn: (tableName: string, from: string, to: string) => string
|
|
10
|
+
renameTable: (from: string, to: string) => string
|
|
11
|
+
rebuildTable: (spec: RebuildTableSpec) => string
|
|
9
12
|
dropTable: (tableName: string) => string
|
|
10
13
|
dropColumn: (tableName: string, columnName: string) => string
|
|
11
14
|
dropIndex: (tableName: string, indexName: string) => string
|
|
@@ -21,6 +24,9 @@ export declare class PostgresDriver implements DialectDriver {
|
|
|
21
24
|
addForeignKey(tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string): string;
|
|
22
25
|
addColumn(tableName: string, column: ColumnPlan): string;
|
|
23
26
|
modifyColumn(tableName: string, column: ColumnPlan): string;
|
|
27
|
+
renameColumn(tableName: string, from: string, to: string): string;
|
|
28
|
+
renameTable(from: string, to: string): string;
|
|
29
|
+
rebuildTable(): string;
|
|
24
30
|
dropTable(tableName: string): string;
|
|
25
31
|
dropColumn(tableName: string, columnName: string): string;
|
|
26
32
|
dropIndex(tableName: string, indexName: string): string;
|
package/dist/drivers/sqlite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnPlan, IndexPlan, TablePlan } from '../migrations';
|
|
1
|
+
import type { ColumnPlan, IndexPlan, RebuildTableSpec, TablePlan } from '../migrations';
|
|
2
2
|
export declare interface DialectDriver {
|
|
3
3
|
createEnumType: (enumTypeName: string, values: string[]) => string
|
|
4
4
|
createTable: (table: TablePlan) => string
|
|
@@ -6,6 +6,9 @@ export declare interface DialectDriver {
|
|
|
6
6
|
addForeignKey: (tableName: string, columnName: string, refTable: string, refColumn: string, onDelete?: string, onUpdate?: string) => string
|
|
7
7
|
addColumn: (tableName: string, column: ColumnPlan) => string
|
|
8
8
|
modifyColumn: (tableName: string, column: ColumnPlan) => string
|
|
9
|
+
renameColumn: (tableName: string, from: string, to: string) => string
|
|
10
|
+
renameTable: (from: string, to: string) => string
|
|
11
|
+
rebuildTable: (spec: RebuildTableSpec) => string
|
|
9
12
|
dropTable: (tableName: string) => string
|
|
10
13
|
dropColumn: (tableName: string, columnName: string) => string
|
|
11
14
|
dropIndex: (tableName: string, indexName: string) => string
|
|
@@ -21,6 +24,9 @@ export declare class SQLiteDriver implements DialectDriver {
|
|
|
21
24
|
addForeignKey(_tableName: string, _columnName: string, _refTable: string, _refColumn: string, _onDelete?: string, _onUpdate?: string): string;
|
|
22
25
|
addColumn(tableName: string, column: ColumnPlan): string;
|
|
23
26
|
modifyColumn(tableName: string, column: ColumnPlan): string;
|
|
27
|
+
renameColumn(tableName: string, from: string, to: string): string;
|
|
28
|
+
renameTable(from: string, to: string): string;
|
|
29
|
+
rebuildTable(spec: RebuildTableSpec): string;
|
|
24
30
|
dropTable(tableName: string): string;
|
|
25
31
|
dropColumn(tableName: string, columnName: string): string;
|
|
26
32
|
dropIndex(tableName: string, indexName: string): string;
|
package/dist/migrations.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ModelRecord, OnForeignKeyAction } from './schema';
|
|
2
2
|
import type { SupportedDialect } from './types';
|
|
3
3
|
export declare function buildMigrationPlan(models: ModelRecord, options: InferenceOptions): MigrationPlan;
|
|
4
|
-
export declare function generateSql(plan: MigrationPlan): string[];
|
|
4
|
+
export declare function generateSql(plan: MigrationPlan, opts?: { dryRun?: boolean }): string[];
|
|
5
5
|
/**
|
|
6
6
|
* Helper function to convert SQL statements array to a single string (for backward compatibility)
|
|
7
7
|
*/
|
|
@@ -15,18 +15,42 @@ export declare function generateDiffSqlString(previous: MigrationPlan | undefine
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function hashMigrationPlan(plan: MigrationPlan): string;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
18
|
+
* The dialect's *physical* storage type for a column. Two model types that
|
|
19
|
+
* collapse to the same physical type produce no real schema change, so the
|
|
20
|
+
* diff should ignore the difference. This is what keeps the live-DB
|
|
21
|
+
* introspection path (where the exact model type can't be recovered) from
|
|
22
|
+
* emitting spurious ALTERs on every run.
|
|
23
|
+
*
|
|
24
|
+
* SQLite is the lossy one (string/text/date/datetime/json all map to TEXT;
|
|
25
|
+
* boolean/integer/bigint to INTEGER; float/double/decimal to REAL). For
|
|
26
|
+
* Postgres/MySQL the normalized type round-trips faithfully enough to compare
|
|
27
|
+
* directly.
|
|
28
|
+
*/
|
|
29
|
+
export declare function canonicalStorageType(col: ColumnPlan, dialect: SupportedDialect): string;
|
|
30
|
+
/**
|
|
31
|
+
* Canonical string form of a column default, so equivalent defaults expressed
|
|
32
|
+
* differently by a live DB vs a model (quoting, casts, `now()` vs
|
|
33
|
+
* `CURRENT_TIMESTAMP`, `0` vs `'0'`) compare equal.
|
|
34
|
+
*/
|
|
35
|
+
export declare function canonicalizeDefault(col: ColumnPlan): string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Generate comprehensive SQL to migrate from a previous plan to a new plan,
|
|
38
|
+
* plus a structured list of the operations involved (so callers can gate
|
|
39
|
+
* destructive changes and report renames without re-parsing SQL).
|
|
40
|
+
*
|
|
41
|
+
* Handles: created/dropped tables, added/dropped/renamed/modified columns,
|
|
42
|
+
* added/dropped indexes, foreign-key changes, and — on SQLite — table rebuilds
|
|
43
|
+
* for changes the dialect can't do in place.
|
|
26
44
|
*
|
|
27
45
|
* If there is no previous plan or the dialect changed, generates full SQL.
|
|
28
46
|
*/
|
|
29
|
-
export declare function
|
|
47
|
+
export declare function generateDiffOperations(previous: MigrationPlan | undefined, next: MigrationPlan, opts?: DiffOptions): DiffResult;
|
|
48
|
+
/**
|
|
49
|
+
* Generate comprehensive SQL to migrate from a previous plan to a new plan.
|
|
50
|
+
* Thin wrapper over {@link generateDiffOperations} preserved for existing
|
|
51
|
+
* callers that only need the raw statements.
|
|
52
|
+
*/
|
|
53
|
+
export declare function generateDiffSql(previous: MigrationPlan | undefined, next: MigrationPlan, opts?: DiffOptions): string[];
|
|
30
54
|
export declare interface ColumnPlan {
|
|
31
55
|
name: string
|
|
32
56
|
type: NormalizedColumnType
|
|
@@ -53,9 +77,46 @@ export declare interface MigrationPlan {
|
|
|
53
77
|
dialect: SupportedDialect
|
|
54
78
|
tables: TablePlan[]
|
|
55
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Inputs for a SQLite table rebuild ("12-step recreate"). SQLite can't
|
|
82
|
+
* `ALTER COLUMN` to change a type, and can't `DROP COLUMN` when the column
|
|
83
|
+
* is a PK / unique / indexed / FK target. The fix is to create a new table
|
|
84
|
+
* with the desired schema, copy data across, drop the old table, and rename
|
|
85
|
+
* the new one into place. See `SQLiteDriver.rebuildTable`.
|
|
86
|
+
*/
|
|
87
|
+
export declare interface RebuildTableSpec {
|
|
88
|
+
target: TablePlan
|
|
89
|
+
tempName: string
|
|
90
|
+
columnSource: Record<string, string>
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* A structured description of one change emitted by the diff engine. Callers
|
|
94
|
+
* (e.g. the Stacks `buddy migrate` command) inspect these to gate destructive
|
|
95
|
+
* changes behind confirmation and to surface rename candidates, instead of
|
|
96
|
+
* re-parsing the raw SQL strings.
|
|
97
|
+
*/
|
|
98
|
+
export declare interface MigrationOperation {
|
|
99
|
+
kind: MigrationOpKind
|
|
100
|
+
table: string
|
|
101
|
+
column?: string
|
|
102
|
+
from?: string
|
|
103
|
+
to?: string
|
|
104
|
+
destructive: boolean
|
|
105
|
+
confidence?: 'high' | 'low'
|
|
106
|
+
sql: string
|
|
107
|
+
}
|
|
108
|
+
/** Result of {@link generateDiffOperations}: raw statements + structured ops. */
|
|
109
|
+
export declare interface DiffResult {
|
|
110
|
+
statements: string[]
|
|
111
|
+
operations: MigrationOperation[]
|
|
112
|
+
}
|
|
56
113
|
export declare interface InferenceOptions {
|
|
57
114
|
dialect: SupportedDialect
|
|
58
115
|
}
|
|
116
|
+
export declare interface DiffOptions {
|
|
117
|
+
applyRenames?: boolean
|
|
118
|
+
dryRun?: boolean
|
|
119
|
+
}
|
|
59
120
|
export type PrimitiveDefault = string | number | boolean | bigint | Date;
|
|
60
121
|
export type NormalizedColumnType = | 'string'
|
|
61
122
|
| 'text'
|
|
@@ -69,3 +130,16 @@ export type NormalizedColumnType = | 'string'
|
|
|
69
130
|
| 'datetime'
|
|
70
131
|
| 'json'
|
|
71
132
|
| 'enum';
|
|
133
|
+
/** The kind of schema change a single migration operation represents. */
|
|
134
|
+
export type MigrationOpKind = | 'create_table'
|
|
135
|
+
| 'drop_table'
|
|
136
|
+
| 'rename_table'
|
|
137
|
+
| 'add_column'
|
|
138
|
+
| 'drop_column'
|
|
139
|
+
| 'modify_column'
|
|
140
|
+
| 'rename_column'
|
|
141
|
+
| 'create_index'
|
|
142
|
+
| 'drop_index'
|
|
143
|
+
| 'add_foreign_key'
|
|
144
|
+
| 'rebuild_table'
|
|
145
|
+
| 'create_enum';
|