Skip to content

Commit

Permalink
feat: migrations structure and example
Browse files Browse the repository at this point in the history
Refs: #23
  • Loading branch information
tshemsedinov committed Sep 12, 2020
1 parent f6340c3 commit 424402c
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 0 deletions.
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: 'timur.shemsedinov@gmail.com' },
],

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: 'timur.shemsedinov@gmail.com' },
],

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: 'timur.shemsedinov@gmail.com' },
],

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;

0 comments on commit 424402c

Please sign in to comment.