-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrations structure and example
Refs: #23
- Loading branch information
1 parent
f6340c3
commit 424402c
Showing
13 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
({ | ||
name: 'example', | ||
description: 'Example database schema', | ||
version: 3, | ||
|
||
authors: [ | ||
{ name: 'Timur Shemsedinov', email: 'timur.shemsedinov@gmail.com' }, | ||
], | ||
|
||
extensions: [ | ||
'hstore', | ||
'postgis', | ||
'postgis_topology', | ||
'pg_trgm', | ||
] | ||
}); |
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,14 @@ | ||
({ | ||
name: 'example', | ||
description: 'Example database schema', | ||
version: 1, | ||
|
||
authors: [ | ||
{ name: 'Timur Shemsedinov', email: 'timur.shemsedinov@gmail.com' }, | ||
], | ||
|
||
extensions: [ | ||
'hstore', | ||
'pg_trgm', | ||
] | ||
}); |
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,4 @@ | ||
({ | ||
country: 'Country', | ||
name: { type: 'string', unique: true }, | ||
}); |
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,3 @@ | ||
({ | ||
name: { type: 'string', unique: true }, | ||
}); |
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,14 @@ | ||
({ | ||
name: 'example', | ||
description: 'Example database schema', | ||
version: 2, | ||
|
||
authors: [ | ||
{ name: 'Timur Shemsedinov', email: 'timur.shemsedinov@gmail.com' }, | ||
], | ||
|
||
extensions: [ | ||
'hstore', | ||
'pg_trgm', | ||
] | ||
}); |
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,4 @@ | ||
({ | ||
country: 'Country', | ||
name: { type: 'string', unique: true }, | ||
}); |
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,4 @@ | ||
({ | ||
planet: 'Planet', | ||
name: { type: 'string', unique: true }, | ||
}); |
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,4 @@ | ||
({ | ||
city: 'City', | ||
name: 'string', | ||
}); |
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,3 @@ | ||
({ | ||
name: 'string', | ||
}); |
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,5 @@ | ||
DROP TABLE "Country"; | ||
DROP TABLE "City"; | ||
|
||
DROP EXTENSION hstore; | ||
DROP EXTENSION pg_trgm; |
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,20 @@ | ||
CREATE EXTENSION hstore; | ||
CREATE EXTENSION pg_trgm; | ||
|
||
CREATE TABLE "Country" ( | ||
"countryId" bigint generated always as identity, | ||
"name" varchar NOT NULL | ||
); | ||
|
||
ALTER TABLE "Country" ADD CONSTRAINT "pkCountry" PRIMARY KEY ("countryId"); | ||
CREATE UNIQUE INDEX "akCountryName" ON "Country" ("name"); | ||
|
||
CREATE TABLE "City" ( | ||
"cityId" bigint generated always as identity, | ||
"countryId" bigint NOT NULL, | ||
"name" varchar NOT NULL | ||
); | ||
|
||
ALTER TABLE "City" ADD CONSTRAINT "pkCity" PRIMARY KEY ("cityId"); | ||
ALTER TABLE "City" ADD CONSTRAINT "fkCityCountry" FOREIGN KEY ("countryId") REFERENCES "Country" ("countryId") ON DELETE CASCADE; | ||
CREATE UNIQUE INDEX "akCityName" ON "City" ("name"); |
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,5 @@ | ||
DROP TABLE "District"; | ||
|
||
ALTER TABLE "Country" DROP COLUMN "planetId"; | ||
|
||
DROP TABLE "Planet"; |
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,19 @@ | ||
CREATE TABLE "Planet" ( | ||
"planetId" bigint generated always as identity, | ||
"name" varchar NOT NULL | ||
); | ||
|
||
ALTER TABLE "Planet" ADD CONSTRAINT "pkPlanet" PRIMARY KEY ("planetId"); | ||
|
||
ALTER TABLE "Country" ADD COLUMN "planetId" bigint NOT NULL ); | ||
|
||
ALTER TABLE "Country" ADD CONSTRAINT "fkCountryPlanet" FOREIGN KEY ("planetId") REFERENCES "Planet" ("planetId") ON DELETE CASCADE; | ||
|
||
CREATE TABLE "District" ( | ||
"districtId" bigint generated always as identity, | ||
"cityId" bigint NOT NULL, | ||
"name" varchar NOT NULL | ||
); | ||
|
||
ALTER TABLE "District" ADD CONSTRAINT "pkDistrict" PRIMARY KEY ("districtId"); | ||
ALTER TABLE "District" ADD CONSTRAINT "fkDistrictCity" FOREIGN KEY ("cityId") REFERENCES "City" ("cityId") ON DELETE CASCADE; |