Skip to content

Commit 1aa4be1

Browse files
committed
Fix sqlite fk issue
1 parent 82ba69e commit 1aa4be1

61 files changed

Lines changed: 1373 additions & 22 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/vespertide-query/src/builder.rs

Lines changed: 488 additions & 9 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE `product` ADD COLUMN `category_id` bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
9+
ALTER TABLE `product` ADD CONSTRAINT `fk_product__category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: Index { name: None, columns: ["category_id"] } }
12+
CREATE INDEX `ix_product__category_id` ON `product` (`category_id`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE "product" ADD COLUMN "category_id" bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
9+
ALTER TABLE "product" ADD CONSTRAINT "fk_product__category_id" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: Index { name: None, columns: ["category_id"] } }
12+
CREATE INDEX "ix_product__category_id" ON "product" ("category_id")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE "product" ADD COLUMN "category_id" bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
9+
CREATE TABLE "product_temp" ( "id" integer, "category_id" bigint, FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE );
10+
INSERT INTO "product_temp" ("id", "category_id") SELECT "id", "category_id" FROM "product";
11+
DROP TABLE "product";
12+
ALTER TABLE "product_temp" RENAME TO "product"
13+
14+
-- Action 2: AddConstraint { table: "product", constraint: Index { name: None, columns: ["category_id"] } }
15+
CREATE INDEX "ix_product__category_id" ON "product" ("category_id")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE `product` ADD COLUMN `category_id` bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: Index { name: None, columns: ["category_id"] } }
9+
CREATE INDEX `ix_product__category_id` ON `product` (`category_id`)
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
12+
ALTER TABLE `product` ADD CONSTRAINT `fk_product__category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE "product" ADD COLUMN "category_id" bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: Index { name: None, columns: ["category_id"] } }
9+
CREATE INDEX "ix_product__category_id" ON "product" ("category_id")
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
12+
ALTER TABLE "product" ADD CONSTRAINT "fk_product__category_id" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE "product" ADD COLUMN "category_id" bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: Index { name: None, columns: ["category_id"] } }
9+
CREATE INDEX "ix_product__category_id" ON "product" ("category_id")
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
12+
CREATE TABLE "product_temp" ( "id" integer, "category_id" bigint, FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE );
13+
INSERT INTO "product_temp" ("id", "category_id") SELECT "id", "category_id" FROM "product";
14+
DROP TABLE "product";
15+
ALTER TABLE "product_temp" RENAME TO "product";
16+
CREATE INDEX "ix_product__category_id" ON "product" ("category_id")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE `product` ADD COLUMN `category_id` bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
9+
ALTER TABLE `product` ADD CONSTRAINT `fk_product__category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`id`) ON DELETE CASCADE
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: Unique { name: None, columns: ["category_id"] } }
12+
CREATE UNIQUE INDEX `uq_product__category_id` ON `product` (`category_id`)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE "product" ADD COLUMN "category_id" bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
9+
ALTER TABLE "product" ADD CONSTRAINT "fk_product__category_id" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE
10+
11+
-- Action 2: AddConstraint { table: "product", constraint: Unique { name: None, columns: ["category_id"] } }
12+
CREATE UNIQUE INDEX "uq_product__category_id" ON "product" ("category_id")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: crates/vespertide-query/src/builder.rs
3+
expression: sql
4+
---
5+
-- Action 0: AddColumn { table: "product", column: ColumnDef { name: "category_id", type: Simple(BigInt), nullable: true, default: None, comment: None, primary_key: None, unique: None, index: None, foreign_key: None }, fill_with: None }
6+
ALTER TABLE "product" ADD COLUMN "category_id" bigint
7+
8+
-- Action 1: AddConstraint { table: "product", constraint: ForeignKey { name: None, columns: ["category_id"], ref_table: "category", ref_columns: ["id"], on_delete: Some(Cascade), on_update: None } }
9+
CREATE TABLE "product_temp" ( "id" integer, "category_id" bigint, FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE );
10+
INSERT INTO "product_temp" ("id", "category_id") SELECT "id", "category_id" FROM "product";
11+
DROP TABLE "product";
12+
ALTER TABLE "product_temp" RENAME TO "product"
13+
14+
-- Action 2: AddConstraint { table: "product", constraint: Unique { name: None, columns: ["category_id"] } }
15+
CREATE UNIQUE INDEX "uq_product__category_id" ON "product" ("category_id")

0 commit comments

Comments
 (0)