Skip to content

Commit 4d38a48

Browse files
committed
add migrations script
1 parent 9b5fe73 commit 4d38a48

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

VinePlus.Database/migrations.sql

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" (
2+
migration_id character varying(150) NOT NULL,
3+
product_version character varying(32) NOT NULL,
4+
CONSTRAINT pk___ef_migrations_history PRIMARY KEY (migration_id)
5+
);
6+
7+
START TRANSACTION;
8+
9+
CREATE TABLE threads (
10+
id integer GENERATED BY DEFAULT AS IDENTITY,
11+
thread jsonb NULL,
12+
board jsonb NULL,
13+
is_pinned boolean NOT NULL,
14+
is_locked boolean NOT NULL,
15+
is_deleted boolean NOT NULL,
16+
type integer NOT NULL,
17+
last_post_no integer NOT NULL,
18+
last_post_page integer NOT NULL,
19+
created timestamp with time zone NOT NULL,
20+
total_posts integer NOT NULL,
21+
total_view integer NOT NULL,
22+
creator jsonb NULL,
23+
comments integer[] NULL,
24+
CONSTRAINT pk_threads PRIMARY KEY (id)
25+
);
26+
27+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
28+
VALUES ('20230422112523_Initial', '7.0.3');
29+
30+
COMMIT;
31+
32+
START TRANSACTION;
33+
34+
ALTER TABLE threads RENAME COLUMN comments TO posts;
35+
36+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
37+
VALUES ('20230426200040_minor change in thread schema', '7.0.3');
38+
39+
COMMIT;
40+
41+
START TRANSACTION;
42+
43+
ALTER TABLE threads DROP COLUMN posts;
44+
45+
CREATE TABLE posts (
46+
id text NOT NULL,
47+
is_comment boolean NOT NULL,
48+
is_deleted boolean NOT NULL,
49+
is_mod_comment boolean NOT NULL,
50+
post_no integer NOT NULL,
51+
creator jsonb NULL,
52+
is_edited boolean NOT NULL,
53+
created timestamp with time zone NOT NULL,
54+
content text NULL,
55+
thread_id integer NOT NULL,
56+
CONSTRAINT pk_posts PRIMARY KEY (id),
57+
CONSTRAINT fk_posts_threads_thread_id FOREIGN KEY (thread_id) REFERENCES threads (id) ON DELETE CASCADE
58+
);
59+
60+
CREATE INDEX ix_posts_thread_id ON posts (thread_id);
61+
62+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
63+
VALUES ('20230427121144_add post entity', '7.0.3');
64+
65+
COMMIT;
66+
67+
START TRANSACTION;
68+
69+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
70+
VALUES ('20230428153019_idk', '7.0.3');
71+
72+
COMMIT;
73+
74+
START TRANSACTION;
75+
76+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
77+
VALUES ('20230516162526_stopped using settings.json', '7.0.3');
78+
79+
COMMIT;
80+
81+
START TRANSACTION;
82+
83+
CREATE INDEX ix_threads_created ON threads (created DESC);
84+
85+
CREATE INDEX ix_posts_created ON posts (created DESC);
86+
87+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
88+
VALUES ('20241223211333_index on thread.created and post.created', '7.0.3');
89+
90+
COMMIT;
91+
92+
START TRANSACTION;
93+
94+
CREATE INDEX ix_posts_creator_text ON posts ((creator->>'Text'));
95+
96+
CREATE INDEX ix_threads_creator_text ON threads ((creator->>'Text'));
97+
98+
INSERT INTO "__EFMigrationsHistory" (migration_id, product_version)
99+
VALUES ('20241223213958_index on thread.creator.text and post.creator.text', '7.0.3');
100+
101+
COMMIT;
102+

VinePlus.Web/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ The database can be hydrated in two methods. You can either download all the dat
3535
- restore the dump to the database with `pg_restore -v -h <postgres-server-address> -U <username> -d <databasename> -j 2 comicvine_seed_v1`
3636
- after a while, all the tables, and data should be restored
3737

38+
## Method 3
39+
- navigate to `VinePlus.Database`
40+
- run `migrations.sql`. this would initialize the schema
41+
- then you can populate the data with either method 1 or 2
42+
3843
The first can be time consuming - especially on low internet speed, while the backup might not have the most recent data
3944

4045
### How to run

0 commit comments

Comments
 (0)