rwsdk 0.1.2 → 0.1.4
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/runtime/lib/db/index.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +21 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +9 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +14 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +13 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +7 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +7 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +10 -0
- package/dist/runtime/lib/db/typeInference/builders/table.js +1 -0
- package/dist/runtime/lib/db/typeInference/database.d.ts +38 -0
- package/dist/runtime/lib/db/typeInference/database.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +105 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +86 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +14 -0
- package/dist/runtime/lib/db/typeInference/utils.js +1 -0
- package/dist/scripts/ensure-deploy-env.mjs +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface AlterColumnBuilder {
|
|
2
|
+
setDataType<T extends string>(dataType: T): AlteredColumnBuilder<"setDataType", T>;
|
|
3
|
+
setDefault<T>(value: T): AlteredColumnBuilder<"setDefault", T>;
|
|
4
|
+
dropDefault(): AlteredColumnBuilder<"dropDefault", true>;
|
|
5
|
+
setNotNull(): AlteredColumnBuilder<"setNotNull", true>;
|
|
6
|
+
dropNotNull(): AlteredColumnBuilder<"dropNotNull", true>;
|
|
7
|
+
}
|
|
8
|
+
export interface AlteredColumnBuilder<Kind extends string, Value> {
|
|
9
|
+
readonly kind: Kind;
|
|
10
|
+
readonly value: Value;
|
|
11
|
+
}
|
|
12
|
+
export type AlterColumnBuilderCallback = (builder: AlterColumnBuilder) => AlteredColumnBuilder<any, any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SqlToTsType, ExecutedBuilder, Prettify } from "../utils";
|
|
2
|
+
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
+
import { AlterColumnBuilderCallback } from "./alterColumn";
|
|
4
|
+
export interface AlterTableBuilder<TName extends string, TSchema extends Record<string, any> = {}> {
|
|
5
|
+
readonly __tableName: TName;
|
|
6
|
+
readonly __addedColumns: TSchema;
|
|
7
|
+
renameTo<TNewName extends string>(newTableName: TNewName): AlterTableBuilder<TNewName, TSchema>;
|
|
8
|
+
setSchema(newSchema: string): AlterTableBuilder<TName, TSchema>;
|
|
9
|
+
addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): AlterTableBuilder<TName, Prettify<TSchema & Record<K, SqlToTsType<T>>>>;
|
|
10
|
+
dropColumn<K extends string>(name: K): AlterTableBuilder<TName, Prettify<TSchema & {
|
|
11
|
+
[P in K]: never;
|
|
12
|
+
}>>;
|
|
13
|
+
renameColumn<KFrom extends string, KTo extends string>(from: KFrom, to: KTo): AlterTableBuilder<TName, Prettify<TSchema & {
|
|
14
|
+
[P in KFrom]: never;
|
|
15
|
+
} & {
|
|
16
|
+
[P in KTo]: any;
|
|
17
|
+
}>>;
|
|
18
|
+
alterColumn<K extends string>(column: K, alteration: AlterColumnBuilderCallback): AlterTableBuilder<TName, TSchema>;
|
|
19
|
+
modifyColumn<K extends string, T extends string>(column: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): AlterTableBuilder<TName, Prettify<TSchema & Record<K, SqlToTsType<T>>>>;
|
|
20
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface ColumnDefinitionBuilder<T = any> {
|
|
2
|
+
primaryKey(): ColumnDefinitionBuilder<T>;
|
|
3
|
+
notNull(): ColumnDefinitionBuilder<T>;
|
|
4
|
+
unique(): ColumnDefinitionBuilder<T>;
|
|
5
|
+
defaultTo<V extends T>(value: V): ColumnDefinitionBuilder<T>;
|
|
6
|
+
references(ref: string): ColumnDefinitionBuilder<T>;
|
|
7
|
+
onDelete(action: "cascade" | "restrict" | "set null"): ColumnDefinitionBuilder<T>;
|
|
8
|
+
unsigned(): ColumnDefinitionBuilder<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SqlToTsType, ExecutedBuilder, Prettify } from "../utils";
|
|
2
|
+
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
+
export interface CreateTableBuilder<TName extends string, TSchema extends Record<string, any> = {}> {
|
|
4
|
+
readonly __tableName: TName;
|
|
5
|
+
readonly __addedColumns: TSchema;
|
|
6
|
+
temporary(): CreateTableBuilder<TName, TSchema>;
|
|
7
|
+
onCommit(onCommit: "preserve rows" | "delete rows" | "drop"): CreateTableBuilder<TName, TSchema>;
|
|
8
|
+
ifNotExists(): CreateTableBuilder<TName, TSchema>;
|
|
9
|
+
addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): CreateTableBuilder<TName, Prettify<TSchema & Record<K, SqlToTsType<T>>>>;
|
|
10
|
+
modifyFront(modifier: string): CreateTableBuilder<TName, TSchema>;
|
|
11
|
+
modifyEnd(modifier: string): CreateTableBuilder<TName, TSchema>;
|
|
12
|
+
as(expression: string): CreateTableBuilder<TName, TSchema>;
|
|
13
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExecutedBuilder } from "../utils";
|
|
2
|
+
export interface CreateViewBuilder<TName extends string, TSchema extends Record<string, any> = {}, TColumns extends string[] = []> {
|
|
3
|
+
readonly __viewName: TName;
|
|
4
|
+
readonly __schema: TSchema;
|
|
5
|
+
readonly __columns: TColumns;
|
|
6
|
+
withSchema<S extends Record<string, any>>(): CreateViewBuilder<TName, S, TColumns>;
|
|
7
|
+
temporary(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
8
|
+
orReplace(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
9
|
+
ifNotExists(): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
10
|
+
columns<C extends string[]>(columns: C): CreateViewBuilder<TName, TSchema, C>;
|
|
11
|
+
as<E extends string>(expression: E): CreateViewBuilder<TName, TSchema, TColumns>;
|
|
12
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TableBuilder } from "./table";
|
|
2
|
+
import { AlterTableBuilder } from "./alterTable";
|
|
3
|
+
import { DropTableBuilder } from "./dropTable";
|
|
4
|
+
import { CreateViewBuilder } from "./createView";
|
|
5
|
+
import { DropViewBuilder } from "./dropView";
|
|
6
|
+
export interface SchemaBuilder {
|
|
7
|
+
createTable<TName extends string>(name: TName): TableBuilder<TName, {}>;
|
|
8
|
+
alterTable<TName extends string>(name: TName): AlterTableBuilder<TName, {}>;
|
|
9
|
+
dropTable<TName extends string>(name: TName): DropTableBuilder<TName>;
|
|
10
|
+
createView<TName extends string>(name: TName): CreateViewBuilder<TName, {}>;
|
|
11
|
+
dropView<TName extends string>(name: TName): DropViewBuilder<TName>;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SqlToTsType, ExecutedBuilder, Prettify } from "../utils";
|
|
2
|
+
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
+
export interface TableBuilder<TName extends string, TSchema extends Record<string, any> = {}> {
|
|
4
|
+
readonly __tableName: TName;
|
|
5
|
+
readonly __schema: TSchema;
|
|
6
|
+
addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): TableBuilder<TName, Prettify<TSchema & Record<K, SqlToTsType<T>>>>;
|
|
7
|
+
temporary(): this;
|
|
8
|
+
ifNotExists(): this;
|
|
9
|
+
execute(): Promise<ExecutedBuilder<this>>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Kysely } from "kysely";
|
|
2
|
+
import { ExecutedBuilder, Prettify, MergeSchemas, OmitNever, UnionToIntersection } from "./utils";
|
|
3
|
+
import { TableBuilder } from "./builders/table";
|
|
4
|
+
import { CreateViewBuilder } from "./builders/createView.js";
|
|
5
|
+
import { AlterTableBuilder } from "./builders/alterTable.js";
|
|
6
|
+
import { DropTableBuilder } from "./builders/dropTable.js";
|
|
7
|
+
import { DropViewBuilder } from "./builders/dropView.js";
|
|
8
|
+
import { SchemaBuilder } from "./builders/schema";
|
|
9
|
+
export interface InferenceBuilder {
|
|
10
|
+
schema: SchemaBuilder;
|
|
11
|
+
}
|
|
12
|
+
export type MigrationBuilder = InferenceBuilder & Kysely<any>;
|
|
13
|
+
export interface Migration<TUpReturn = unknown> {
|
|
14
|
+
up(db: MigrationBuilder): TUpReturn;
|
|
15
|
+
down?(db: Kysely<any>): any;
|
|
16
|
+
}
|
|
17
|
+
export type Migrations = Record<string, Migration>;
|
|
18
|
+
type GetBuilder<T> = T extends ExecutedBuilder<infer B> ? B : never;
|
|
19
|
+
type BuildersFromMigration<TMigration extends Migration> = TMigration extends Migration<infer TUpReturn> ? Awaited<TUpReturn> extends Array<infer Item> ? GetBuilder<Item> : GetBuilder<Awaited<TUpReturn>> : never;
|
|
20
|
+
type AllBuilders<TMigrations extends Migrations> = BuildersFromMigration<TMigrations[keyof TMigrations]>;
|
|
21
|
+
type CreatedTables<TMigrations extends Migrations> = UnionToIntersection<ExtractTableSchema<Extract<AllBuilders<TMigrations>, TableBuilder<any, any>>>>;
|
|
22
|
+
type CreatedViews<TMigrations extends Migrations> = UnionToIntersection<ExtractViewSchema<Extract<AllBuilders<TMigrations>, CreateViewBuilder<any, any>>>>;
|
|
23
|
+
type AlteredTables<TMigrations extends Migrations> = UnionToIntersection<ExtractAlterSchema<Extract<AllBuilders<TMigrations>, AlterTableBuilder<any, any>>>>;
|
|
24
|
+
type DroppedTableNames<TMigrations extends Migrations> = ExtractDroppedTableName<Extract<AllBuilders<TMigrations>, DropTableBuilder<any>>>;
|
|
25
|
+
type DroppedViewNames<TMigrations extends Migrations> = ExtractDroppedViewName<Extract<AllBuilders<TMigrations>, DropViewBuilder<any>>>;
|
|
26
|
+
type AllCreated<TMigrations extends Migrations> = MergeSchemas<CreatedTables<TMigrations>, CreatedViews<TMigrations>>;
|
|
27
|
+
type MergedSchemaBeforeDrop<TMigrations extends Migrations> = MergeSchemas<AllCreated<TMigrations>, AlteredTables<TMigrations>>;
|
|
28
|
+
type CleanedSchema<T> = {
|
|
29
|
+
[K in keyof T]: OmitNever<T[K]>;
|
|
30
|
+
};
|
|
31
|
+
type InferredDatabase<TMigrations extends Migrations> = Omit<Omit<CleanedSchema<MergedSchemaBeforeDrop<TMigrations>>, DroppedTableNames<TMigrations>>, DroppedViewNames<TMigrations>>;
|
|
32
|
+
export type Database<TMigrations extends Migrations = Migrations> = Prettify<InferredDatabase<TMigrations>>;
|
|
33
|
+
export type ExtractTableSchema<T> = T extends TableBuilder<infer TName, infer TSchema> ? Record<TName, TSchema> : never;
|
|
34
|
+
export type ExtractViewSchema<T> = T extends CreateViewBuilder<infer TName, infer TSchema> ? Record<TName, TSchema> : never;
|
|
35
|
+
export type ExtractAlterSchema<T> = T extends AlterTableBuilder<infer TName, infer TSchema> ? Record<TName, TSchema> : never;
|
|
36
|
+
export type ExtractDroppedTableName<T> = T extends DropTableBuilder<infer TName> ? TName : never;
|
|
37
|
+
export type ExtractDroppedViewName<T> = T extends DropViewBuilder<infer TName> ? TName : never;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
(_it = "alterTable addColumn") => {
|
|
2
|
+
const migrations = {
|
|
3
|
+
"0": {
|
|
4
|
+
async up(db) {
|
|
5
|
+
return [
|
|
6
|
+
await db.schema
|
|
7
|
+
.createTable("users")
|
|
8
|
+
.addColumn("username", "text", (col) => col.notNull().unique())
|
|
9
|
+
.execute(),
|
|
10
|
+
];
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
"1": {
|
|
14
|
+
async up(db) {
|
|
15
|
+
return [
|
|
16
|
+
await db.schema
|
|
17
|
+
.alterTable("users")
|
|
18
|
+
.addColumn("displayName", "text")
|
|
19
|
+
.execute(),
|
|
20
|
+
];
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
(_test) => { };
|
|
25
|
+
};
|
|
26
|
+
(_it = "alterTable renameColumn and dropColumn") => {
|
|
27
|
+
const migrations = {
|
|
28
|
+
"0": {
|
|
29
|
+
async up(db) {
|
|
30
|
+
return [
|
|
31
|
+
await db.schema
|
|
32
|
+
.createTable("users")
|
|
33
|
+
.addColumn("username", "text")
|
|
34
|
+
.addColumn("displayName", "text")
|
|
35
|
+
.execute(),
|
|
36
|
+
];
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
"1": {
|
|
40
|
+
async up(db) {
|
|
41
|
+
return [
|
|
42
|
+
await db.schema
|
|
43
|
+
.alterTable("users")
|
|
44
|
+
.renameColumn("displayName", "nickname")
|
|
45
|
+
.dropColumn("username")
|
|
46
|
+
.execute(),
|
|
47
|
+
];
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
(_test) => { };
|
|
52
|
+
};
|
|
53
|
+
(_it = "alterTable alterColumn setDataType and setDefault") => {
|
|
54
|
+
const migrations = {
|
|
55
|
+
"0": {
|
|
56
|
+
async up(db) {
|
|
57
|
+
return [
|
|
58
|
+
db.schema.createTable("users").addColumn("age", "integer").execute(),
|
|
59
|
+
];
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
"1": {
|
|
63
|
+
async up(db) {
|
|
64
|
+
return [
|
|
65
|
+
db.schema
|
|
66
|
+
.alterTable("users")
|
|
67
|
+
.alterColumn("age", (col) => col.setDataType("text"))
|
|
68
|
+
.alterColumn("age", (col) => col.setDefault("unknown"))
|
|
69
|
+
.execute(),
|
|
70
|
+
];
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
// todo(justinvdm, 2024-01-08): Support setDataType()
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
(_test) => { };
|
|
77
|
+
};
|
|
78
|
+
(_it = "alterTable alterColumn dropDefault, setNotNull, dropNotNull") => {
|
|
79
|
+
const migrations = {
|
|
80
|
+
"0": {
|
|
81
|
+
async up(db) {
|
|
82
|
+
return [
|
|
83
|
+
await db.schema
|
|
84
|
+
.createTable("users")
|
|
85
|
+
.addColumn("age", "integer")
|
|
86
|
+
.execute(),
|
|
87
|
+
];
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
"1": {
|
|
91
|
+
async up(db) {
|
|
92
|
+
return [
|
|
93
|
+
await db.schema
|
|
94
|
+
.alterTable("users")
|
|
95
|
+
.alterColumn("age", (col) => col.dropDefault())
|
|
96
|
+
.alterColumn("age", (col) => col.setNotNull())
|
|
97
|
+
.alterColumn("age", (col) => col.dropNotNull())
|
|
98
|
+
.execute(),
|
|
99
|
+
];
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
(_test) => { };
|
|
104
|
+
};
|
|
105
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
(_it = "createTable") => {
|
|
2
|
+
const migrations = {
|
|
3
|
+
"001_init": {
|
|
4
|
+
async up(db) {
|
|
5
|
+
return [
|
|
6
|
+
await db.schema
|
|
7
|
+
.createTable("users")
|
|
8
|
+
.addColumn("username", "text", (col) => col.notNull().unique())
|
|
9
|
+
.execute(),
|
|
10
|
+
];
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
(_test) => { };
|
|
15
|
+
};
|
|
16
|
+
(_it = "createTable with multiple columns and defaults") => {
|
|
17
|
+
const migrations = {
|
|
18
|
+
"001_init": {
|
|
19
|
+
async up(db) {
|
|
20
|
+
return [
|
|
21
|
+
await db.schema
|
|
22
|
+
.createTable("users")
|
|
23
|
+
.addColumn("username", "text", (col) => col.notNull())
|
|
24
|
+
.addColumn("age", "integer", (col) => col.defaultTo(18))
|
|
25
|
+
.addColumn("active", "boolean", (col) => col.defaultTo(true))
|
|
26
|
+
.execute(),
|
|
27
|
+
];
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
(_test) => { };
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
(_it = "dropTable") => {
|
|
2
|
+
const migrations = {
|
|
3
|
+
"0": {
|
|
4
|
+
async up(db) {
|
|
5
|
+
return [
|
|
6
|
+
await db.schema
|
|
7
|
+
.createTable("users")
|
|
8
|
+
.addColumn("username", "text", (col) => col.notNull().unique())
|
|
9
|
+
.execute(),
|
|
10
|
+
await db.schema
|
|
11
|
+
.createTable("posts")
|
|
12
|
+
.addColumn("title", "text")
|
|
13
|
+
.execute(),
|
|
14
|
+
];
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
"1": {
|
|
18
|
+
async up(db) {
|
|
19
|
+
return [await db.schema.dropTable("posts").execute()];
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
(_test) => { };
|
|
24
|
+
};
|
|
25
|
+
(_it = "dropTable non-existent table") => {
|
|
26
|
+
const migrations = {
|
|
27
|
+
"0": {
|
|
28
|
+
async up(db) {
|
|
29
|
+
return [await db.schema.dropTable("ghost").execute()];
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
(_test) => { };
|
|
34
|
+
};
|
|
35
|
+
(_it = "dropTable all tables") => {
|
|
36
|
+
const migrations = {
|
|
37
|
+
"0": {
|
|
38
|
+
async up(db) {
|
|
39
|
+
return [
|
|
40
|
+
await db.schema.createTable("a").addColumn("x", "text").execute(),
|
|
41
|
+
await db.schema.createTable("b").addColumn("y", "text").execute(),
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"1": {
|
|
46
|
+
async up(db) {
|
|
47
|
+
return [
|
|
48
|
+
await db.schema.dropTable("a").execute(),
|
|
49
|
+
await db.schema.dropTable("b").execute(),
|
|
50
|
+
];
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
(_test) => { };
|
|
55
|
+
};
|
|
56
|
+
(_it = "chaining createTable and dropTable") => {
|
|
57
|
+
const migrations = {
|
|
58
|
+
"0": {
|
|
59
|
+
async up(db) {
|
|
60
|
+
return [
|
|
61
|
+
await db.schema
|
|
62
|
+
.createTable("users")
|
|
63
|
+
.addColumn("username", "text")
|
|
64
|
+
.execute(),
|
|
65
|
+
await db.schema
|
|
66
|
+
.createTable("posts")
|
|
67
|
+
.addColumn("title", "text")
|
|
68
|
+
.execute(),
|
|
69
|
+
];
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
"1": {
|
|
73
|
+
async up(db) {
|
|
74
|
+
return [
|
|
75
|
+
await db.schema.dropTable("posts").execute(),
|
|
76
|
+
await db.schema
|
|
77
|
+
.createTable("comments")
|
|
78
|
+
.addColumn("text", "text")
|
|
79
|
+
.execute(),
|
|
80
|
+
];
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
(_test) => { };
|
|
85
|
+
};
|
|
86
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
(_it = "addColumn with default value") => {
|
|
2
|
+
const migrations = {
|
|
3
|
+
"0": {
|
|
4
|
+
async up(db) {
|
|
5
|
+
return [
|
|
6
|
+
await db.schema
|
|
7
|
+
.createTable("users")
|
|
8
|
+
.addColumn("username", "text", (col) => col.notNull().unique())
|
|
9
|
+
.addColumn("posts", "integer", (col) => col.defaultTo(0).notNull())
|
|
10
|
+
.execute(),
|
|
11
|
+
];
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
(_test) => { };
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type SqlToTsType<T extends string> = T extends "text" ? string : T extends "integer" ? number : T extends "blob" ? Uint8Array : T extends "real" ? number : T extends "boolean" ? boolean : never;
|
|
2
|
+
export type Prettify<T> = {
|
|
3
|
+
[K in keyof T]: T[K];
|
|
4
|
+
} & {};
|
|
5
|
+
export type ExecutedBuilder<T> = {
|
|
6
|
+
__builder_type: T;
|
|
7
|
+
};
|
|
8
|
+
export type MergeSchemas<A, B> = {
|
|
9
|
+
[K in keyof A | keyof B]: K extends keyof A ? K extends keyof B ? Prettify<A[K] & B[K]> : A[K] : K extends keyof B ? B[K] : never;
|
|
10
|
+
};
|
|
11
|
+
export type OmitNever<T> = {
|
|
12
|
+
[K in keyof T as T[K] extends never ? never : K]: T[K];
|
|
13
|
+
};
|
|
14
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -14,6 +14,12 @@ const promptForDeployment = async () => {
|
|
|
14
14
|
output: process.stdout,
|
|
15
15
|
});
|
|
16
16
|
return new Promise((resolve) => {
|
|
17
|
+
// Handle Ctrl+C (SIGINT)
|
|
18
|
+
rl.on('SIGINT', () => {
|
|
19
|
+
rl.close();
|
|
20
|
+
console.log('\nDeployment cancelled.');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
});
|
|
17
23
|
rl.question("Do you want to proceed with deployment? (y/N): ", (answer) => {
|
|
18
24
|
rl.close();
|
|
19
25
|
resolve(answer.toLowerCase() === "y");
|