Skip to content

Commit 3d13ec8

Browse files
committed
Add drop for type and removed if not exists
- added drop of the type - removed if not exists on table creation - added a better explaination as to why the reverse ordering is needed
1 parent 4b62240 commit 3d13ec8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

@app/db/migrations/current.sql

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@ example of a table that could be created after setup complete
66
- uncomment the statements below
77
- save the file and graphile-migrate will update the schema into database automagically
88
- any "drop" statements should be at the top (in reverse order)
9+
reverse order as we could have references
10+
from the second created table to the first created table
11+
12+
here is an pseudo example:
13+
DROP C;
14+
DROP B;
15+
DROP A;
16+
CREATE A;
17+
CREATE B;
18+
CREATE C;
19+
20+
if references exists from B -> A
21+
we have to DROP B before DROP A we have references that point to A from B
22+
23+
In the example below post and feed need to be
24+
deleted in reverse order due to feed -> post
925
*/
1026

11-
-- drop table if exists feed;
12-
-- drop table if exists post;
27+
-- UNCOMMENT FROM HERE --
28+
29+
-- drop table if exists app_public.feed;
30+
-- drop table if exists app_public.post;
31+
32+
-- drop type if exists app_public.post_topic;
1333

1434
-- create type app_public.post_topic as enum (
1535
-- 'discussion',
@@ -18,7 +38,7 @@ example of a table that could be created after setup complete
1838
-- 'showcase'
1939
-- );
2040

21-
-- create table if not exists app_public.post (
41+
-- create table app_public.post (
2242
-- id serial primary key,
2343
-- author_id integer not null references app_public.users(id),
2444
-- headline text not null check (char_length(headline) < 280),
@@ -35,7 +55,7 @@ example of a table that could be created after setup complete
3555
-- comment on column app_public.post.body is 'the main body text of our post.';
3656
-- comment on column app_public.post.created_at is 'the time this post was created.';
3757

38-
-- create table if not exists app_public.feed (
58+
-- create table app_public.feed (
3959
-- id serial primary key,
4060
-- posts integer not null references app_public.post(id),
4161
-- created_at timestamp default now()

0 commit comments

Comments
 (0)