Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations structure and example #24

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/schema/.database.js
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: '[email protected]' },
],

extensions: [
'hstore',
'postgis',
'postgis_topology',
'pg_trgm',
]
});
14 changes: 14 additions & 0 deletions test/schema/.history/2020-09-11-v1/.database.js
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: '[email protected]' },
],

extensions: [
'hstore',
'pg_trgm',
]
});
4 changes: 4 additions & 0 deletions test/schema/.history/2020-09-11-v1/City.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
({
country: 'Country',
name: { type: 'string', unique: true },
});
3 changes: 3 additions & 0 deletions test/schema/.history/2020-09-11-v1/Country.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
name: { type: 'string', unique: true },
});
14 changes: 14 additions & 0 deletions test/schema/.history/2020-09-11-v2/.database.js
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: '[email protected]' },
],

extensions: [
'hstore',
'pg_trgm',
]
});
4 changes: 4 additions & 0 deletions test/schema/.history/2020-09-11-v2/City.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
({
country: 'Country',
name: { type: 'string', unique: true },
});
4 changes: 4 additions & 0 deletions test/schema/.history/2020-09-11-v2/Country.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
({
planet: 'Planet',
name: { type: 'string', unique: true },
});
4 changes: 4 additions & 0 deletions test/schema/.history/2020-09-11-v2/District.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
({
city: 'City',
name: 'string',
});
3 changes: 3 additions & 0 deletions test/schema/.history/2020-09-11-v2/Planet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
({
name: 'string',
});
5 changes: 5 additions & 0 deletions test/schema/.migrations/2020-09-11-v1-dn.sql
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;
20 changes: 20 additions & 0 deletions test/schema/.migrations/2020-09-11-v1-up.sql
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");
5 changes: 5 additions & 0 deletions test/schema/.migrations/2020-09-11-v2-dn.sql
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";
19 changes: 19 additions & 0 deletions test/schema/.migrations/2020-09-11-v2-up.sql
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;