@rudderjs/database 1.1.0 → 1.2.0
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/README.md +70 -0
- package/dist/db.d.ts +21 -3
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +27 -5
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -4
- package/dist/index.js.map +1 -1
- package/dist/native/adapter.d.ts +202 -0
- package/dist/native/adapter.d.ts.map +1 -0
- package/dist/native/adapter.js +440 -0
- package/dist/native/adapter.js.map +1 -0
- package/dist/native/compiler.d.ts +371 -0
- package/dist/native/compiler.d.ts.map +1 -0
- package/dist/native/compiler.js +978 -0
- package/dist/native/compiler.js.map +1 -0
- package/dist/native/dialect-mysql.d.ts +26 -0
- package/dist/native/dialect-mysql.d.ts.map +1 -0
- package/dist/native/dialect-mysql.js +188 -0
- package/dist/native/dialect-mysql.js.map +1 -0
- package/dist/native/dialect-pg.d.ts +26 -0
- package/dist/native/dialect-pg.d.ts.map +1 -0
- package/dist/native/dialect-pg.js +192 -0
- package/dist/native/dialect-pg.js.map +1 -0
- package/dist/native/dialect.d.ts +255 -0
- package/dist/native/dialect.d.ts.map +1 -0
- package/dist/native/dialect.js +237 -0
- package/dist/native/dialect.js.map +1 -0
- package/dist/native/driver.d.ts +37 -0
- package/dist/native/driver.d.ts.map +1 -0
- package/dist/native/driver.js +19 -0
- package/dist/native/driver.js.map +1 -0
- package/dist/native/drivers/better-sqlite3.d.ts +56 -0
- package/dist/native/drivers/better-sqlite3.d.ts.map +1 -0
- package/dist/native/drivers/better-sqlite3.js +171 -0
- package/dist/native/drivers/better-sqlite3.js.map +1 -0
- package/dist/native/drivers/mysql.d.ts +30 -0
- package/dist/native/drivers/mysql.d.ts.map +1 -0
- package/dist/native/drivers/mysql.js +176 -0
- package/dist/native/drivers/mysql.js.map +1 -0
- package/dist/native/drivers/postgres.d.ts +57 -0
- package/dist/native/drivers/postgres.d.ts.map +1 -0
- package/dist/native/drivers/postgres.js +155 -0
- package/dist/native/drivers/postgres.js.map +1 -0
- package/dist/native/errors.d.ts +43 -0
- package/dist/native/errors.d.ts.map +1 -0
- package/dist/native/errors.js +64 -0
- package/dist/native/errors.js.map +1 -0
- package/dist/native/index.d.ts +27 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +55 -0
- package/dist/native/index.js.map +1 -0
- package/dist/native/isolation.d.ts +14 -0
- package/dist/native/isolation.d.ts.map +1 -0
- package/dist/native/isolation.js +37 -0
- package/dist/native/isolation.js.map +1 -0
- package/dist/native/query-builder.d.ts +303 -0
- package/dist/native/query-builder.d.ts.map +1 -0
- package/dist/native/query-builder.js +984 -0
- package/dist/native/query-builder.js.map +1 -0
- package/dist/native/replica-picker.d.ts +22 -0
- package/dist/native/replica-picker.d.ts.map +1 -0
- package/dist/native/replica-picker.js +65 -0
- package/dist/native/replica-picker.js.map +1 -0
- package/dist/native/schema/alter-blueprint.d.ts +37 -0
- package/dist/native/schema/alter-blueprint.d.ts.map +1 -0
- package/dist/native/schema/alter-blueprint.js +56 -0
- package/dist/native/schema/alter-blueprint.js.map +1 -0
- package/dist/native/schema/blueprint.d.ts +151 -0
- package/dist/native/schema/blueprint.d.ts.map +1 -0
- package/dist/native/schema/blueprint.js +286 -0
- package/dist/native/schema/blueprint.js.map +1 -0
- package/dist/native/schema/column.d.ts +168 -0
- package/dist/native/schema/column.d.ts.map +1 -0
- package/dist/native/schema/column.js +190 -0
- package/dist/native/schema/column.js.map +1 -0
- package/dist/native/schema/ddl-compiler.d.ts +34 -0
- package/dist/native/schema/ddl-compiler.d.ts.map +1 -0
- package/dist/native/schema/ddl-compiler.js +352 -0
- package/dist/native/schema/ddl-compiler.js.map +1 -0
- package/dist/native/schema/inspect.d.ts +67 -0
- package/dist/native/schema/inspect.d.ts.map +1 -0
- package/dist/native/schema/inspect.js +312 -0
- package/dist/native/schema/inspect.js.map +1 -0
- package/dist/native/schema/introspect.d.ts +34 -0
- package/dist/native/schema/introspect.d.ts.map +1 -0
- package/dist/native/schema/introspect.js +101 -0
- package/dist/native/schema/introspect.js.map +1 -0
- package/dist/native/schema/migration.d.ts +8 -0
- package/dist/native/schema/migration.d.ts.map +1 -0
- package/dist/native/schema/migration.js +19 -0
- package/dist/native/schema/migration.js.map +1 -0
- package/dist/native/schema/migrator.d.ts +144 -0
- package/dist/native/schema/migrator.d.ts.map +1 -0
- package/dist/native/schema/migrator.js +239 -0
- package/dist/native/schema/migrator.js.map +1 -0
- package/dist/native/schema/rebuild.d.ts +11 -0
- package/dist/native/schema/rebuild.d.ts.map +1 -0
- package/dist/native/schema/rebuild.js +92 -0
- package/dist/native/schema/rebuild.js.map +1 -0
- package/dist/native/schema/schema-builder.d.ts +46 -0
- package/dist/native/schema/schema-builder.d.ts.map +1 -0
- package/dist/native/schema/schema-builder.js +153 -0
- package/dist/native/schema/schema-builder.js.map +1 -0
- package/dist/native/schema/schema-facade.d.ts +63 -0
- package/dist/native/schema/schema-facade.d.ts.map +1 -0
- package/dist/native/schema/schema-facade.js +124 -0
- package/dist/native/schema/schema-facade.js.map +1 -0
- package/dist/native/schema/schema-types.d.ts +27 -0
- package/dist/native/schema/schema-types.d.ts.map +1 -0
- package/dist/native/schema/schema-types.js +52 -0
- package/dist/native/schema/schema-types.js.map +1 -0
- package/dist/native/schema/types-generator.d.ts +73 -0
- package/dist/native/schema/types-generator.d.ts.map +1 -0
- package/dist/native/schema/types-generator.js +181 -0
- package/dist/native/schema/types-generator.js.map +1 -0
- package/dist/registry-bridge.d.ts +24 -4
- package/dist/registry-bridge.d.ts.map +1 -1
- package/dist/registry-bridge.js +20 -0
- package/dist/registry-bridge.js.map +1 -1
- package/dist/sticky.d.ts +22 -0
- package/dist/sticky.d.ts.map +1 -0
- package/dist/sticky.js +61 -0
- package/dist/sticky.js.map +1 -0
- package/package.json +32 -2
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// ─── Database/table inspection (db:show / db:table) ────────
|
|
2
|
+
//
|
|
3
|
+
// Catalog readers behind the `rudder db:show` / `rudder db:table` CLI commands
|
|
4
|
+
// (Laravel's `db:show` / `db:table` analogs). Node-capable, reads via an
|
|
5
|
+
// {@link Executor} + {@link Dialect} pair — same seam as `introspect.ts`, whose
|
|
6
|
+
// `readColumns` this reuses for the per-table column listing.
|
|
7
|
+
//
|
|
8
|
+
// Unlike `readTables` (which feeds the types generator and so excludes the
|
|
9
|
+
// `migrations` bookkeeping table), inspection lists EVERY user table —
|
|
10
|
+
// `migrations` is a real table and an inspection tool shouldn't hide it.
|
|
11
|
+
//
|
|
12
|
+
// Per-dialect notes:
|
|
13
|
+
// - sqlite: PRAGMAs can't take bound params — table names interpolate via
|
|
14
|
+
// `quoteId` AFTER an existence check against the catalog (so `db:table` only
|
|
15
|
+
// ever splices a name the catalog itself reported). Per-table sizes come
|
|
16
|
+
// from the `dbstat` virtual table when the build ships it (try/catch — many
|
|
17
|
+
// don't); the whole-DB size from `page_count * page_size` always works.
|
|
18
|
+
// - pg: `information_schema` for tables/views, `pg_total_relation_size` for
|
|
19
|
+
// sizes, `pg_index`/`pg_constraint` for indexes/FKs (information_schema
|
|
20
|
+
// can't pair composite-FK columns reliably; `unnest WITH ORDINALITY` can).
|
|
21
|
+
// - mysql: `information_schema` throughout (`statistics` for indexes,
|
|
22
|
+
// `key_column_usage` + `referential_constraints` for FKs).
|
|
23
|
+
import { readColumns } from './introspect.js';
|
|
24
|
+
// ─── Shared catalog reads ──────────────────────────────────
|
|
25
|
+
/** Every user table including `migrations` (the types-generator exclusion in
|
|
26
|
+
* `readTables` doesn't apply to inspection). */
|
|
27
|
+
async function listTables(executor, dialect) {
|
|
28
|
+
if (dialect.name === 'pg') {
|
|
29
|
+
const rows = await executor.execute(`SELECT table_name AS name FROM information_schema.tables ` +
|
|
30
|
+
`WHERE table_schema = current_schema() AND table_type = 'BASE TABLE' ORDER BY table_name`, []);
|
|
31
|
+
return rows.map((r) => String(r['name']));
|
|
32
|
+
}
|
|
33
|
+
if (dialect.name === 'mysql') {
|
|
34
|
+
const rows = await executor.execute(`SELECT table_name AS name FROM information_schema.tables ` +
|
|
35
|
+
`WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE' ORDER BY table_name`, []);
|
|
36
|
+
return rows.map((r) => String(r['name'] ?? r['NAME'] ?? r['TABLE_NAME']));
|
|
37
|
+
}
|
|
38
|
+
const rows = await executor.execute(`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name`, []);
|
|
39
|
+
return rows.map((r) => String(r['name']));
|
|
40
|
+
}
|
|
41
|
+
async function scalar(executor, sql, bindings = []) {
|
|
42
|
+
const rows = await executor.execute(sql, bindings);
|
|
43
|
+
const first = rows[0];
|
|
44
|
+
if (!first)
|
|
45
|
+
return null;
|
|
46
|
+
const key = Object.keys(first)[0];
|
|
47
|
+
return key === undefined ? null : first[key];
|
|
48
|
+
}
|
|
49
|
+
async function countRows(executor, dialect, table) {
|
|
50
|
+
return Number(await scalar(executor, `SELECT COUNT(*) AS c FROM ${dialect.quoteId(table)}`));
|
|
51
|
+
}
|
|
52
|
+
/** Per-table sizes keyed by table name; empty map when the dialect can't say. */
|
|
53
|
+
async function readSizes(executor, dialect) {
|
|
54
|
+
const sizes = new Map();
|
|
55
|
+
if (dialect.name === 'pg') {
|
|
56
|
+
const rows = await executor.execute(`SELECT table_name AS name, pg_total_relation_size(format('%I.%I', table_schema, table_name)) AS size ` +
|
|
57
|
+
`FROM information_schema.tables WHERE table_schema = current_schema() AND table_type = 'BASE TABLE'`, []);
|
|
58
|
+
for (const r of rows)
|
|
59
|
+
sizes.set(String(r['name']), Number(r['size']));
|
|
60
|
+
return sizes;
|
|
61
|
+
}
|
|
62
|
+
if (dialect.name === 'mysql') {
|
|
63
|
+
const rows = await executor.execute(`SELECT table_name AS name, data_length + index_length AS size ` +
|
|
64
|
+
`FROM information_schema.tables WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE'`, []);
|
|
65
|
+
for (const r of rows)
|
|
66
|
+
sizes.set(String(r['name'] ?? r['NAME'] ?? r['TABLE_NAME']), Number(r['size'] ?? r['SIZE']));
|
|
67
|
+
return sizes;
|
|
68
|
+
}
|
|
69
|
+
// sqlite: dbstat is an optional compile-time module — absent on many builds.
|
|
70
|
+
try {
|
|
71
|
+
const rows = await executor.execute(`SELECT name, SUM(pgsize) AS size FROM dbstat GROUP BY name`, []);
|
|
72
|
+
for (const r of rows)
|
|
73
|
+
sizes.set(String(r['name']), Number(r['size']));
|
|
74
|
+
}
|
|
75
|
+
catch { /* no dbstat — sizes stay null */ }
|
|
76
|
+
return sizes;
|
|
77
|
+
}
|
|
78
|
+
// ─── db:show ───────────────────────────────────────────────
|
|
79
|
+
export async function inspectDatabase(executor, dialect, opts = {}) {
|
|
80
|
+
const names = await listTables(executor, dialect);
|
|
81
|
+
const sizes = await readSizes(executor, dialect);
|
|
82
|
+
let version;
|
|
83
|
+
let database;
|
|
84
|
+
if (dialect.name === 'pg') {
|
|
85
|
+
version = String(await scalar(executor, `SELECT current_setting('server_version') AS v`) ?? '') || null;
|
|
86
|
+
database = String(await scalar(executor, `SELECT current_database() AS db`) ?? '') || null;
|
|
87
|
+
}
|
|
88
|
+
else if (dialect.name === 'mysql') {
|
|
89
|
+
version = String(await scalar(executor, `SELECT VERSION() AS v`) ?? '') || null;
|
|
90
|
+
database = String(await scalar(executor, `SELECT DATABASE() AS db`) ?? '') || null;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
version = String(await scalar(executor, `SELECT sqlite_version() AS v`) ?? '') || null;
|
|
94
|
+
const list = await executor.execute(`PRAGMA database_list`, []);
|
|
95
|
+
const main = list.find((r) => String(r['name']) === 'main');
|
|
96
|
+
const file = main ? String(main['file'] ?? '') : '';
|
|
97
|
+
database = file === '' ? null : file;
|
|
98
|
+
}
|
|
99
|
+
const tables = [];
|
|
100
|
+
for (const name of names) {
|
|
101
|
+
const summary = { name, sizeBytes: sizes.get(name) ?? null };
|
|
102
|
+
if (opts.counts) {
|
|
103
|
+
// Per-table COUNT(*) races concurrent DDL on a shared database — a table
|
|
104
|
+
// the catalog just listed can be dropped before its count runs (a
|
|
105
|
+
// migration mid-`db:show`, or parallel live-test suites on one CI
|
|
106
|
+
// database). A vanished/unreadable table keeps `rows` undefined instead
|
|
107
|
+
// of failing the whole overview; the renderer shows `—`.
|
|
108
|
+
try {
|
|
109
|
+
summary.rows = await countRows(executor, dialect, name);
|
|
110
|
+
}
|
|
111
|
+
catch { /* dropped mid-scan */ }
|
|
112
|
+
}
|
|
113
|
+
tables.push(summary);
|
|
114
|
+
}
|
|
115
|
+
const info = { dialect: dialect.name, version, database, tables };
|
|
116
|
+
if (opts.views)
|
|
117
|
+
info.views = await listViews(executor, dialect);
|
|
118
|
+
return info;
|
|
119
|
+
}
|
|
120
|
+
async function listViews(executor, dialect) {
|
|
121
|
+
if (dialect.name === 'pg') {
|
|
122
|
+
const rows = await executor.execute(`SELECT table_name AS name FROM information_schema.views WHERE table_schema = current_schema() ORDER BY table_name`, []);
|
|
123
|
+
return rows.map((r) => String(r['name']));
|
|
124
|
+
}
|
|
125
|
+
if (dialect.name === 'mysql') {
|
|
126
|
+
const rows = await executor.execute(`SELECT table_name AS name FROM information_schema.views WHERE table_schema = DATABASE() ORDER BY table_name`, []);
|
|
127
|
+
return rows.map((r) => String(r['name'] ?? r['NAME'] ?? r['TABLE_NAME']));
|
|
128
|
+
}
|
|
129
|
+
const rows = await executor.execute(`SELECT name FROM sqlite_master WHERE type = 'view' ORDER BY name`, []);
|
|
130
|
+
return rows.map((r) => String(r['name']));
|
|
131
|
+
}
|
|
132
|
+
// ─── db:table ──────────────────────────────────────────────
|
|
133
|
+
/** Inspect one table — null when the table doesn't exist (the caller renders
|
|
134
|
+
* the available-tables hint). The existence check doubles as the injection
|
|
135
|
+
* gate: PRAGMA/`COUNT(*)` interpolation only ever sees the catalog's own
|
|
136
|
+
* spelling of the name, never the raw CLI argument. */
|
|
137
|
+
export async function inspectTable(executor, dialect, table) {
|
|
138
|
+
const names = await listTables(executor, dialect);
|
|
139
|
+
const name = names.find((n) => n === table);
|
|
140
|
+
if (name === undefined)
|
|
141
|
+
return null;
|
|
142
|
+
const [columns, indexes, foreignKeys, rows, sizes] = [
|
|
143
|
+
await readColumns(executor, dialect, name),
|
|
144
|
+
await readIndexes(executor, dialect, name),
|
|
145
|
+
await readForeignKeys(executor, dialect, name),
|
|
146
|
+
await countRows(executor, dialect, name),
|
|
147
|
+
await readSizes(executor, dialect),
|
|
148
|
+
];
|
|
149
|
+
return { name, columns, indexes, foreignKeys, rows, sizeBytes: sizes.get(name) ?? null };
|
|
150
|
+
}
|
|
151
|
+
/** A table's indexes. On sqlite an INTEGER PRIMARY KEY is the rowid — no index
|
|
152
|
+
* row exists for it, so a `PRIMARY` pseudo-entry is synthesized from the
|
|
153
|
+
* column PK ordinals (mirrors Laravel's SQLite schema reader). */
|
|
154
|
+
export async function readIndexes(executor, dialect, table) {
|
|
155
|
+
if (dialect.name === 'pg') {
|
|
156
|
+
const rows = await executor.execute(`SELECT i.relname AS name, ix.indisunique AS is_unique, ix.indisprimary AS is_primary, ` +
|
|
157
|
+
`a.attname AS col, array_position(ix.indkey::int2[], a.attnum) AS pos ` +
|
|
158
|
+
`FROM pg_index ix ` +
|
|
159
|
+
`JOIN pg_class i ON i.oid = ix.indexrelid ` +
|
|
160
|
+
`JOIN pg_class t ON t.oid = ix.indrelid ` +
|
|
161
|
+
`JOIN pg_namespace n ON n.oid = t.relnamespace ` +
|
|
162
|
+
`JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) ` +
|
|
163
|
+
`WHERE t.relname = ${dialect.placeholder(0)} AND n.nspname = current_schema() ` +
|
|
164
|
+
`ORDER BY i.relname, pos`, [table]);
|
|
165
|
+
return groupIndexRows(rows.map((r) => ({
|
|
166
|
+
name: String(r['name']),
|
|
167
|
+
col: String(r['col']),
|
|
168
|
+
unique: r['is_unique'] === true || r['is_unique'] === 't',
|
|
169
|
+
primary: r['is_primary'] === true || r['is_primary'] === 't',
|
|
170
|
+
})));
|
|
171
|
+
}
|
|
172
|
+
if (dialect.name === 'mysql') {
|
|
173
|
+
const rows = await executor.execute(`SELECT index_name AS name, non_unique, column_name AS col ` +
|
|
174
|
+
`FROM information_schema.statistics ` +
|
|
175
|
+
`WHERE table_schema = DATABASE() AND table_name = ${dialect.placeholder(0)} ` +
|
|
176
|
+
`ORDER BY index_name, seq_in_index`, [table]);
|
|
177
|
+
return groupIndexRows(rows.map((r) => {
|
|
178
|
+
const name = String(r['name'] ?? r['NAME'] ?? r['INDEX_NAME']);
|
|
179
|
+
return {
|
|
180
|
+
name,
|
|
181
|
+
col: String(r['col'] ?? r['COL'] ?? r['COLUMN_NAME']),
|
|
182
|
+
unique: Number(r['non_unique'] ?? r['NON_UNIQUE']) === 0,
|
|
183
|
+
primary: name === 'PRIMARY',
|
|
184
|
+
};
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
const indexes = [];
|
|
188
|
+
const list = await executor.execute(`PRAGMA index_list(${dialect.quoteId(table)})`, []);
|
|
189
|
+
for (const ix of list) {
|
|
190
|
+
const ixName = String(ix['name']);
|
|
191
|
+
const info = await executor.execute(`PRAGMA index_info(${dialect.quoteId(ixName)})`, []);
|
|
192
|
+
indexes.push({
|
|
193
|
+
name: ixName,
|
|
194
|
+
columns: info.map((r) => String(r['name'])),
|
|
195
|
+
unique: Number(ix['unique']) === 1,
|
|
196
|
+
primary: String(ix['origin']) === 'pk',
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (!indexes.some((ix) => ix.primary)) {
|
|
200
|
+
const pkCols = (await readColumns(executor, dialect, table))
|
|
201
|
+
.filter((c) => c.pk > 0)
|
|
202
|
+
.sort((a, b) => a.pk - b.pk)
|
|
203
|
+
.map((c) => c.name);
|
|
204
|
+
if (pkCols.length > 0)
|
|
205
|
+
indexes.unshift({ name: 'PRIMARY', columns: pkCols, unique: true, primary: true });
|
|
206
|
+
}
|
|
207
|
+
return indexes;
|
|
208
|
+
}
|
|
209
|
+
/** Fold per-column index rows (already ordered by index then position) into
|
|
210
|
+
* one entry per index. */
|
|
211
|
+
function groupIndexRows(rows) {
|
|
212
|
+
const byName = new Map();
|
|
213
|
+
for (const r of rows) {
|
|
214
|
+
const entry = byName.get(r.name);
|
|
215
|
+
if (entry)
|
|
216
|
+
entry.columns.push(r.col);
|
|
217
|
+
else
|
|
218
|
+
byName.set(r.name, { name: r.name, columns: [r.col], unique: r.unique, primary: r.primary });
|
|
219
|
+
}
|
|
220
|
+
return [...byName.values()];
|
|
221
|
+
}
|
|
222
|
+
/** pg `pg_constraint` action codes → SQL keywords. */
|
|
223
|
+
const PG_FK_ACTIONS = {
|
|
224
|
+
a: 'NO ACTION', r: 'RESTRICT', c: 'CASCADE', n: 'SET NULL', d: 'SET DEFAULT',
|
|
225
|
+
};
|
|
226
|
+
/** A table's outbound foreign keys, composite columns paired in order. */
|
|
227
|
+
export async function readForeignKeys(executor, dialect, table) {
|
|
228
|
+
if (dialect.name === 'pg') {
|
|
229
|
+
// information_schema can't pair composite-FK columns; unnest the conkey /
|
|
230
|
+
// confkey arrays WITH ORDINALITY so columns[i] ↔ foreignColumns[i] holds.
|
|
231
|
+
const rows = await executor.execute(`SELECT c.conname AS name, ft.relname AS foreign_table, ` +
|
|
232
|
+
`(SELECT string_agg(a.attname, ',' ORDER BY k.ord) FROM unnest(c.conkey) WITH ORDINALITY AS k(attnum, ord) ` +
|
|
233
|
+
` JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = k.attnum) AS cols, ` +
|
|
234
|
+
`(SELECT string_agg(a.attname, ',' ORDER BY k.ord) FROM unnest(c.confkey) WITH ORDINALITY AS k(attnum, ord) ` +
|
|
235
|
+
` JOIN pg_attribute a ON a.attrelid = c.confrelid AND a.attnum = k.attnum) AS foreign_cols, ` +
|
|
236
|
+
`c.confupdtype AS upd, c.confdeltype AS del ` +
|
|
237
|
+
`FROM pg_constraint c ` +
|
|
238
|
+
`JOIN pg_class t ON t.oid = c.conrelid ` +
|
|
239
|
+
`JOIN pg_class ft ON ft.oid = c.confrelid ` +
|
|
240
|
+
`JOIN pg_namespace n ON n.oid = t.relnamespace ` +
|
|
241
|
+
`WHERE c.contype = 'f' AND t.relname = ${dialect.placeholder(0)} AND n.nspname = current_schema() ` +
|
|
242
|
+
`ORDER BY c.conname`, [table]);
|
|
243
|
+
return rows.map((r) => ({
|
|
244
|
+
name: String(r['name']),
|
|
245
|
+
columns: String(r['cols'] ?? '').split(',').filter(Boolean),
|
|
246
|
+
foreignTable: String(r['foreign_table']),
|
|
247
|
+
foreignColumns: String(r['foreign_cols'] ?? '').split(',').filter(Boolean),
|
|
248
|
+
onUpdate: PG_FK_ACTIONS[String(r['upd'])] ?? null,
|
|
249
|
+
onDelete: PG_FK_ACTIONS[String(r['del'])] ?? null,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
if (dialect.name === 'mysql') {
|
|
253
|
+
const rows = await executor.execute(`SELECT kcu.constraint_name AS name, kcu.column_name AS col, ` +
|
|
254
|
+
`kcu.referenced_table_name AS foreign_table, kcu.referenced_column_name AS foreign_col, ` +
|
|
255
|
+
`rc.update_rule AS upd, rc.delete_rule AS del ` +
|
|
256
|
+
`FROM information_schema.key_column_usage kcu ` +
|
|
257
|
+
`JOIN information_schema.referential_constraints rc ` +
|
|
258
|
+
`ON rc.constraint_schema = kcu.constraint_schema AND rc.constraint_name = kcu.constraint_name ` +
|
|
259
|
+
`WHERE kcu.table_schema = DATABASE() AND kcu.table_name = ${dialect.placeholder(0)} ` +
|
|
260
|
+
`AND kcu.referenced_table_name IS NOT NULL ` +
|
|
261
|
+
`ORDER BY kcu.constraint_name, kcu.ordinal_position`, [table]);
|
|
262
|
+
const byName = new Map();
|
|
263
|
+
for (const r of rows) {
|
|
264
|
+
const name = String(r['name'] ?? r['NAME'] ?? r['CONSTRAINT_NAME']);
|
|
265
|
+
const entry = byName.get(name);
|
|
266
|
+
const col = String(r['col'] ?? r['COL'] ?? r['COLUMN_NAME']);
|
|
267
|
+
const foreignCol = String(r['foreign_col'] ?? r['FOREIGN_COL'] ?? r['REFERENCED_COLUMN_NAME']);
|
|
268
|
+
if (entry) {
|
|
269
|
+
entry.columns.push(col);
|
|
270
|
+
entry.foreignColumns.push(foreignCol);
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
byName.set(name, {
|
|
274
|
+
name,
|
|
275
|
+
columns: [col],
|
|
276
|
+
foreignTable: String(r['foreign_table'] ?? r['FOREIGN_TABLE'] ?? r['REFERENCED_TABLE_NAME']),
|
|
277
|
+
foreignColumns: [foreignCol],
|
|
278
|
+
onUpdate: String(r['upd'] ?? r['UPD'] ?? r['UPDATE_RULE'] ?? '') || null,
|
|
279
|
+
onDelete: String(r['del'] ?? r['DEL'] ?? r['DELETE_RULE'] ?? '') || null,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return [...byName.values()];
|
|
284
|
+
}
|
|
285
|
+
// sqlite: PRAGMA rows are one-per-column-pair, grouped by `id`. `to` is null
|
|
286
|
+
// when the FK references the parent's implicit primary key.
|
|
287
|
+
const rows = await executor.execute(`PRAGMA foreign_key_list(${dialect.quoteId(table)})`, []);
|
|
288
|
+
const byId = new Map();
|
|
289
|
+
for (const r of rows) {
|
|
290
|
+
const id = Number(r['id']);
|
|
291
|
+
const entry = byId.get(id);
|
|
292
|
+
const col = String(r['from']);
|
|
293
|
+
const foreignCol = r['to'] == null ? null : String(r['to']);
|
|
294
|
+
if (entry) {
|
|
295
|
+
entry.columns.push(col);
|
|
296
|
+
if (foreignCol !== null)
|
|
297
|
+
entry.foreignColumns.push(foreignCol);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
byId.set(id, {
|
|
301
|
+
name: null,
|
|
302
|
+
columns: [col],
|
|
303
|
+
foreignTable: String(r['table']),
|
|
304
|
+
foreignColumns: foreignCol === null ? [] : [foreignCol],
|
|
305
|
+
onUpdate: String(r['on_update'] ?? '') || null,
|
|
306
|
+
onDelete: String(r['on_delete'] ?? '') || null,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return [...byId.values()];
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=inspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../../../src/native/schema/inspect.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,+EAA+E;AAC/E,yEAAyE;AACzE,gFAAgF;AAChF,8DAA8D;AAC9D,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,yEAAyE;AACzE,EAAE;AACF,qBAAqB;AACrB,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,gFAAgF;AAChF,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,wEAAwE;AACxE,+DAA+D;AAI/D,OAAO,EAAE,WAAW,EAAkB,MAAM,iBAAiB,CAAA;AAuD7D,8DAA8D;AAE9D;iDACiD;AACjD,KAAK,UAAU,UAAU,CAAC,QAAkB,EAAE,OAAgB;IAC5D,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CACjC,2DAA2D;YAC3D,yFAAyF,EACzF,EAAE,CACH,CAAA;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CACjC,2DAA2D;YAC3D,mFAAmF,EACnF,EAA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C,IAAI,CAAC,CAAC,CAAA;QAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC1B,MAAM,GAAG,GAAU,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QACpC,MAAM,UAAU,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAC3D,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACvB,IAAI,UAAU,KAAK,IAAI;gBAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QAChE,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;gBACX,IAAI,EAAY,IAAI;gBACpB,OAAO,EAAS,CAAC,GAAG,CAAC;gBACrB,YAAY,EAAI,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBAClC,cAAc,EAAE,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;gBACvD,QAAQ,EAAQ,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;gBACpD,QAAQ,EAAQ,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI;aACrD,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Executor } from '../driver.js';
|
|
2
|
+
import type { Dialect } from '../dialect.js';
|
|
3
|
+
/** One column as reported by `PRAGMA table_info`. */
|
|
4
|
+
export interface RawColumn {
|
|
5
|
+
name: string;
|
|
6
|
+
/** Declared type string, e.g. `TEXT`, `INTEGER`, `NUMERIC`. */
|
|
7
|
+
type: string;
|
|
8
|
+
notNull: boolean;
|
|
9
|
+
/** Default as a raw SQL literal string (`0`, `'x'`, `CURRENT_TIMESTAMP`) or
|
|
10
|
+
* null when the column has no default. Re-emitted verbatim — it's already
|
|
11
|
+
* valid SQL from the catalog. */
|
|
12
|
+
dflt: string | null;
|
|
13
|
+
/** 1-based position in the primary key, or 0 if not part of it. */
|
|
14
|
+
pk: number;
|
|
15
|
+
}
|
|
16
|
+
/** Every user table name, excluding the framework's own `migrations` bookkeeping
|
|
17
|
+
* table (and SQLite internal `sqlite_*`) — neither belongs in generated model
|
|
18
|
+
* types. Postgres reads the current schema's base tables; SQLite reads
|
|
19
|
+
* `sqlite_master`. */
|
|
20
|
+
export declare function readTables(executor: Executor, dialect: Dialect): Promise<string[]>;
|
|
21
|
+
/** Read a table's columns — Postgres via `information_schema.columns`, SQLite via
|
|
22
|
+
* `PRAGMA table_info`. The `pk` ordinal is only meaningful on SQLite (the
|
|
23
|
+
* rebuild path); on Postgres it's left 0 because PK columns are `NOT NULL`, so
|
|
24
|
+
* `notNull` already drives the type generator's nullability rule. */
|
|
25
|
+
export declare function readColumns(executor: Executor, dialect: Dialect, table: string): Promise<RawColumn[]>;
|
|
26
|
+
/** The `CREATE INDEX` statements for a table's user-created indexes (auto-indexes
|
|
27
|
+
* from PRIMARY KEY / UNIQUE constraints have a null `sql` and are excluded — the
|
|
28
|
+
* rebuilt table re-derives those from its own definition). */
|
|
29
|
+
export declare function readIndexSql(executor: Executor, table: string): Promise<string[]>;
|
|
30
|
+
/** Whether `table` uses `AUTOINCREMENT` (registered in `sqlite_sequence`). The
|
|
31
|
+
* `sqlite_sequence` table only exists once some table declares AUTOINCREMENT,
|
|
32
|
+
* so a missing-table error means "no". */
|
|
33
|
+
export declare function isAutoincrement(executor: Executor, table: string): Promise<boolean>;
|
|
34
|
+
//# sourceMappingURL=introspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../../../src/native/schema/introspect.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,qDAAqD;AACrD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAK,MAAM,CAAA;IACf,+DAA+D;IAC/D,IAAI,EAAK,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB;;sCAEkC;IAClC,IAAI,EAAK,MAAM,GAAG,IAAI,CAAA;IACtB,mEAAmE;IACnE,EAAE,EAAO,MAAM,CAAA;CAChB;AAED;;;uBAGuB;AACvB,wBAAsB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0BxF;AAED;;;sEAGsE;AACtE,wBAAsB,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CA8C3G;AAED;;+DAE+D;AAC/D,wBAAsB,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAMvF;AAED;;2CAE2C;AAC3C,wBAAsB,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOzF"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// ─── Schema introspection (catalog reads) ──────────────────
|
|
2
|
+
//
|
|
3
|
+
// Node-capable (reads via an {@link Executor}). Two consumers:
|
|
4
|
+
// 1. The SQLite table REBUILD — SQLite can't change/drop a column's type in
|
|
5
|
+
// place, so a `.change()` triggers a 12-step rebuild (create shadow → copy
|
|
6
|
+
// → drop → rename → reindex); to build the shadow faithfully we read the
|
|
7
|
+
// live column set, the primary key, autoincrement-ness, and user indexes.
|
|
8
|
+
// 2. The schema→types generator (`collectSchemaTypes`) — `readTables` +
|
|
9
|
+
// `readColumns` feed the `.d.ts` emitter on every dialect.
|
|
10
|
+
//
|
|
11
|
+
// `readTables` / `readColumns` branch on `dialect.name`: SQLite via PRAGMA +
|
|
12
|
+
// `sqlite_master`, Postgres (7.7) and MySQL (7.8) via `information_schema`. The
|
|
13
|
+
// rebuild-only helpers below (`readIndexSql`, `isAutoincrement`) stay
|
|
14
|
+
// SQLite-specific — the rebuild dance is a SQLite workaround pg/mysql don't need.
|
|
15
|
+
/** Every user table name, excluding the framework's own `migrations` bookkeeping
|
|
16
|
+
* table (and SQLite internal `sqlite_*`) — neither belongs in generated model
|
|
17
|
+
* types. Postgres reads the current schema's base tables; SQLite reads
|
|
18
|
+
* `sqlite_master`. */
|
|
19
|
+
export async function readTables(executor, dialect) {
|
|
20
|
+
if (dialect.name === 'pg') {
|
|
21
|
+
const rows = await executor.execute(`SELECT table_name AS name FROM information_schema.tables ` +
|
|
22
|
+
`WHERE table_schema = current_schema() AND table_type = 'BASE TABLE' AND table_name != 'migrations' ` +
|
|
23
|
+
`ORDER BY table_name`, []);
|
|
24
|
+
return rows.map((r) => String(r['name']));
|
|
25
|
+
}
|
|
26
|
+
if (dialect.name === 'mysql') {
|
|
27
|
+
// MySQL information_schema scoped to the connection's current database
|
|
28
|
+
// (`DATABASE()`); same migrations-table exclusion as pg.
|
|
29
|
+
const rows = await executor.execute(`SELECT table_name AS name FROM information_schema.tables ` +
|
|
30
|
+
`WHERE table_schema = DATABASE() AND table_type = 'BASE TABLE' AND table_name != 'migrations' ` +
|
|
31
|
+
`ORDER BY table_name`, []);
|
|
32
|
+
return rows.map((r) => String(r['name']));
|
|
33
|
+
}
|
|
34
|
+
const rows = await executor.execute(`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name != 'migrations' ORDER BY name`, []);
|
|
35
|
+
return rows.map((r) => String(r['name']));
|
|
36
|
+
}
|
|
37
|
+
/** Read a table's columns — Postgres via `information_schema.columns`, SQLite via
|
|
38
|
+
* `PRAGMA table_info`. The `pk` ordinal is only meaningful on SQLite (the
|
|
39
|
+
* rebuild path); on Postgres it's left 0 because PK columns are `NOT NULL`, so
|
|
40
|
+
* `notNull` already drives the type generator's nullability rule. */
|
|
41
|
+
export async function readColumns(executor, dialect, table) {
|
|
42
|
+
if (dialect.name === 'pg') {
|
|
43
|
+
const rows = await executor.execute(`SELECT column_name, data_type, is_nullable, column_default ` +
|
|
44
|
+
`FROM information_schema.columns ` +
|
|
45
|
+
`WHERE table_schema = current_schema() AND table_name = ${dialect.placeholder(0)} ` +
|
|
46
|
+
`ORDER BY ordinal_position`, [table]);
|
|
47
|
+
return rows.map((r) => ({
|
|
48
|
+
name: String(r['column_name']),
|
|
49
|
+
type: String(r['data_type'] ?? ''),
|
|
50
|
+
notNull: String(r['is_nullable']).toUpperCase() === 'NO',
|
|
51
|
+
dflt: r['column_default'] == null ? null : String(r['column_default']),
|
|
52
|
+
pk: 0,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
if (dialect.name === 'mysql') {
|
|
56
|
+
// MySQL's information_schema column names come back lowercased here (the
|
|
57
|
+
// server is case-insensitive on the query side). `data_type` is the base
|
|
58
|
+
// type WITHOUT length/precision (e.g. `tinyint`, not `tinyint(1)`), so the
|
|
59
|
+
// type generator's `tinyint → number` mapping is correct and a `boolean`
|
|
60
|
+
// cast refines it. `pk` stays 0 — `notNull` drives the nullability rule.
|
|
61
|
+
const rows = await executor.execute(`SELECT column_name, data_type, is_nullable, column_default ` +
|
|
62
|
+
`FROM information_schema.columns ` +
|
|
63
|
+
`WHERE table_schema = DATABASE() AND table_name = ${dialect.placeholder(0)} ` +
|
|
64
|
+
`ORDER BY ordinal_position`, [table]);
|
|
65
|
+
return rows.map((r) => ({
|
|
66
|
+
name: String(r['column_name'] ?? r['COLUMN_NAME']),
|
|
67
|
+
type: String(r['data_type'] ?? r['DATA_TYPE'] ?? ''),
|
|
68
|
+
notNull: String(r['is_nullable'] ?? r['IS_NULLABLE']).toUpperCase() === 'NO',
|
|
69
|
+
dflt: (r['column_default'] ?? r['COLUMN_DEFAULT']) == null ? null : String(r['column_default'] ?? r['COLUMN_DEFAULT']),
|
|
70
|
+
pk: 0,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
const rows = await executor.execute(`PRAGMA table_info(${dialect.quoteId(table)})`, []);
|
|
74
|
+
return rows.map((r) => ({
|
|
75
|
+
name: String(r['name']),
|
|
76
|
+
type: String(r['type'] ?? ''),
|
|
77
|
+
notNull: Number(r['notnull']) === 1,
|
|
78
|
+
dflt: r['dflt_value'] == null ? null : String(r['dflt_value']),
|
|
79
|
+
pk: Number(r['pk'] ?? 0),
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
/** The `CREATE INDEX` statements for a table's user-created indexes (auto-indexes
|
|
83
|
+
* from PRIMARY KEY / UNIQUE constraints have a null `sql` and are excluded — the
|
|
84
|
+
* rebuilt table re-derives those from its own definition). */
|
|
85
|
+
export async function readIndexSql(executor, table) {
|
|
86
|
+
const rows = await executor.execute(`SELECT sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ? AND sql IS NOT NULL`, [table]);
|
|
87
|
+
return rows.map((r) => String(r['sql']));
|
|
88
|
+
}
|
|
89
|
+
/** Whether `table` uses `AUTOINCREMENT` (registered in `sqlite_sequence`). The
|
|
90
|
+
* `sqlite_sequence` table only exists once some table declares AUTOINCREMENT,
|
|
91
|
+
* so a missing-table error means "no". */
|
|
92
|
+
export async function isAutoincrement(executor, table) {
|
|
93
|
+
try {
|
|
94
|
+
const rows = await executor.execute(`SELECT 1 FROM sqlite_sequence WHERE name = ?`, [table]);
|
|
95
|
+
return rows.length > 0;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=introspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspect.js","sourceRoot":"","sources":["../../../src/native/schema/introspect.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,+DAA+D;AAC/D,8EAA8E;AAC9E,gFAAgF;AAChF,8EAA8E;AAC9E,+EAA+E;AAC/E,0EAA0E;AAC1E,gEAAgE;AAChE,EAAE;AACF,6EAA6E;AAC7E,gFAAgF;AAChF,sEAAsE;AACtE,kFAAkF;AAmBlF;;;uBAGuB;AACvB,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,QAAkB,EAAE,OAAgB;IACnE,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CACjC,2DAA2D;YAC3D,qGAAqG;YACrG,qBAAqB,EACrB,EAAE,CACH,CAAA;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,uEAAuE;QACvE,yDAAyD;QACzD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CACjC,2DAA2D;YAC3D,+FAA+F;YAC/F,qBAAqB,EACrB,EAAE,CACH,CAAA;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CACjC,yHAAyH,EACzH,EAAE,CACH,CAAA;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CA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AAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC9B,CAAC,CAAC,CAAA;AACL,CAAC;AAED;;+DAE+D;AAC/D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAkB,EAAE,KAAa;IAClE,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CACjC,yFAAyF,EACzF,CAAC,KAAK,CAAC,CACR,CAAA;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;AAC1C,CAAC;AAED;;2CAE2C;AAC3C,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAkB,EAAE,KAAa;IACrE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,8CAA8C,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;QAC5F,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare abstract class Migration {
|
|
2
|
+
/** Apply the migration. */
|
|
3
|
+
abstract up(): Promise<void> | void;
|
|
4
|
+
/** Revert the migration. Defaults to a no-op so a forward-only migration can
|
|
5
|
+
* omit it (rollback of such a migration then does nothing for that step). */
|
|
6
|
+
down(): Promise<void> | void;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=migration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/native/schema/migration.ts"],"names":[],"mappings":"AAcA,8BAAsB,SAAS;IAC7B,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAEnC;kFAC8E;IAC9E,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;CAC7B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// ─── Migration base class (Laravel parity) ─────────────────
|
|
2
|
+
//
|
|
3
|
+
// A migration file default-exports a subclass with `up()` (apply) and `down()`
|
|
4
|
+
// (revert). The runner ({@link Migrator}) binds a connection to the static
|
|
5
|
+
// `Schema` facade, then calls `up()` / `down()` — inside which `Schema.create`,
|
|
6
|
+
// `Schema.drop`, etc. operate on that connection.
|
|
7
|
+
//
|
|
8
|
+
// // database/migrations/2026_05_31_120000_create_users_table.ts
|
|
9
|
+
// import { Migration, Schema } from '@rudderjs/database' // ('@rudderjs/orm/native' still works)
|
|
10
|
+
// export default class extends Migration {
|
|
11
|
+
// async up() { await Schema.create('users', (t) => { t.id(); t.string('name'); t.timestamps() }) }
|
|
12
|
+
// async down() { await Schema.dropIfExists('users') }
|
|
13
|
+
// }
|
|
14
|
+
export class Migration {
|
|
15
|
+
/** Revert the migration. Defaults to a no-op so a forward-only migration can
|
|
16
|
+
* omit it (rollback of such a migration then does nothing for that step). */
|
|
17
|
+
down() { }
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sourceRoot":"","sources":["../../../src/native/schema/migration.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,+EAA+E;AAC/E,2EAA2E;AAC3E,gFAAgF;AAChF,kDAAkD;AAClD,EAAE;AACF,mEAAmE;AACnE,qGAAqG;AACrG,6CAA6C;AAC7C,yGAAyG;AACzG,0DAA0D;AAC1D,MAAM;AAEN,MAAM,OAAgB,SAAS;IAI7B;kFAC8E;IAC9E,IAAI,KAA0B,CAAC;CAChC"}
|