-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
variable "dialect" { | ||
type = string | ||
} | ||
|
||
locals { | ||
dev_url = { | ||
mysql = "docker://mysql/8/dev" | ||
postgres = "docker://postgres/15" | ||
sqlite = "sqlite://file::memory:?cache=shared" | ||
}[var.dialect] | ||
} | ||
|
||
data "external_schema" "gorm" { | ||
program = [ | ||
"go", | ||
"run", | ||
"-mod=mod", | ||
"ariga.io/atlas-provider-gorm", | ||
"load", | ||
"--path", "./models", | ||
"--dialect", var.dialect, | ||
] | ||
} | ||
|
||
env "gorm" { | ||
src = data.external_schema.gorm.url | ||
dev = local.dev_url | ||
migration { | ||
dir = "file://migrations/${var.dialect}" | ||
} | ||
format { | ||
migrate { | ||
diff = "{{ sql . \" \" }}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Create "users" table | ||
CREATE TABLE `users` ( | ||
`id` bigint unsigned NOT NULL AUTO_INCREMENT, | ||
`created_at` datetime(3) NULL, | ||
`updated_at` datetime(3) NULL, | ||
`deleted_at` datetime(3) NULL, | ||
`name` longtext NULL, | ||
PRIMARY KEY (`id`), | ||
INDEX `idx_users_deleted_at` (`deleted_at`) | ||
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; | ||
-- Create "pets" table | ||
CREATE TABLE `pets` ( | ||
`id` bigint unsigned NOT NULL AUTO_INCREMENT, | ||
`created_at` datetime(3) NULL, | ||
`updated_at` datetime(3) NULL, | ||
`deleted_at` datetime(3) NULL, | ||
`name` longtext NULL, | ||
`user_id` bigint unsigned NULL, | ||
PRIMARY KEY (`id`), | ||
INDEX `fk_users_pets` (`user_id`), | ||
INDEX `idx_pets_deleted_at` (`deleted_at`), | ||
CONSTRAINT `fk_users_pets` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION | ||
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1:+pZfwCMvS/gKqnOmiZuH5hVicgjUCn1eiV/m8xwCjP4= | ||
20230627123246.sql h1:+bgzC3WJyyIR6Rv/FUvaNXJ1gkbKJlYcEMgp69yORIY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- Create "users" table | ||
CREATE TABLE "public"."users" ( | ||
"id" bigserial NOT NULL, | ||
"created_at" timestamptz NULL, | ||
"updated_at" timestamptz NULL, | ||
"deleted_at" timestamptz NULL, | ||
"name" text NULL, | ||
PRIMARY KEY ("id") | ||
); | ||
-- Create index "idx_users_deleted_at" to table: "users" | ||
CREATE INDEX "idx_users_deleted_at" ON "public"."users" ("deleted_at"); | ||
-- Create "pets" table | ||
CREATE TABLE "public"."pets" ( | ||
"id" bigserial NOT NULL, | ||
"created_at" timestamptz NULL, | ||
"updated_at" timestamptz NULL, | ||
"deleted_at" timestamptz NULL, | ||
"name" text NULL, | ||
"user_id" bigint NULL, | ||
PRIMARY KEY ("id"), | ||
CONSTRAINT "fk_users_pets" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON UPDATE NO ACTION ON DELETE NO ACTION | ||
); | ||
-- Create index "idx_pets_deleted_at" to table: "pets" | ||
CREATE INDEX "idx_pets_deleted_at" ON "public"."pets" ("deleted_at"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1:pXrvfywo43u1iE6XyKM8H/22j6XzEbkl+H8vJv2dEqM= | ||
20230627123049.sql h1:1jYJM2+VCr9152vg6gayCrcEvuT/FE7ufOyZ86VLaOE= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
-- Create "users" table | ||
CREATE TABLE `users` ( | ||
`id` integer NULL, | ||
`created_at` datetime NULL, | ||
`updated_at` datetime NULL, | ||
`deleted_at` datetime NULL, | ||
`name` text NULL, | ||
PRIMARY KEY (`id`) | ||
); | ||
-- Create index "idx_users_deleted_at" to table: "users" | ||
CREATE INDEX `idx_users_deleted_at` ON `users` (`deleted_at`); | ||
-- Create "pets" table | ||
CREATE TABLE `pets` ( | ||
`id` integer NULL, | ||
`created_at` datetime NULL, | ||
`updated_at` datetime NULL, | ||
`deleted_at` datetime NULL, | ||
`name` text NULL, | ||
`user_id` integer NULL, | ||
PRIMARY KEY (`id`), | ||
CONSTRAINT `fk_users_pets` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION | ||
); | ||
-- Create index "idx_pets_deleted_at" to table: "pets" | ||
CREATE INDEX `idx_pets_deleted_at` ON `pets` (`deleted_at`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1:cm5y8e8m7yaqwWh9/So2zgxG+kuzUnMSdoOGLLxKnLk= | ||
20230627123228.sql h1:YfwJdN73sWz1G5/0tU2BtGLyzJCfRQr8blTSquUZ+qo= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters