File tree Expand file tree Collapse file tree 3 files changed +3
-48
lines changed Expand file tree Collapse file tree 3 files changed +3
-48
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -2,9 +2,7 @@ version: "3.8"
2
2
3
3
services :
4
4
db :
5
- build :
6
- context : .
7
- dockerfile : Dockerfile.database
5
+ image : postgres
8
6
restart : always
9
7
environment :
10
8
# these parameters may be set in .env file, or through normal env setting
Original file line number Diff line number Diff line change 1
1
use error_stack:: Result ;
2
2
use sqlx:: { Pool , Postgres } ;
3
3
4
- pub async fn initialize_database ( conn : & Pool < Postgres > ) -> Result < ( ) , sqlx:: Error > {
5
- // create the supermarket table
6
- sqlx:: query (
7
- r#"CREATE TABLE IF NOT EXISTS countdown_products (
8
- id SERIAL PRIMARY KEY,
9
- name VARCHAR(255) NOT NULL,
10
- barcode VARCHAR(13) NOT NULL,
11
- sku VARCHAR(10) NOT NULL UNIQUE
12
- )"# ,
13
- )
14
- . execute ( conn)
15
- . await ?;
16
-
17
- sqlx:: query (
18
- r#"CREATE TABLE IF NOT EXISTS products (
19
- id SERIAL PRIMARY KEY,
20
- countdown_id INT,
21
-
22
- CONSTRAINT fk_countdown_product
23
- FOREIGN KEY(countdown_id)
24
- REFERENCES countdown_products(id)
25
- )"# ,
26
- )
27
- . execute ( conn)
28
- . await ?;
29
-
30
- sqlx:: query (
31
- r#"CREATE TABLE IF NOT EXISTS prices (
32
- id SERIAL PRIMARY KEY,
33
- product_id INTEGER NOT NULL,
34
- time TIMESTAMPTZ NOT NULL DEFAULT NOW(),
35
- cost_in_cents INTEGER NOT NULL,
36
- supermarket VARCHAR(255) NOT NULL,
37
-
38
- CONSTRAINT fk_product
39
- FOREIGN KEY(product_id)
40
- REFERENCES products(id)
41
- )"# ,
42
- )
43
- . execute ( conn)
44
- . await ?;
4
+ pub async fn initialize_database ( conn : & Pool < Postgres > ) -> Result < ( ) , sqlx:: migrate:: MigrateError > {
5
+ sqlx:: migrate!( ) . run ( conn) . await ?;
45
6
46
7
Ok ( ( ) )
47
8
}
You can’t perform that action at this time.
0 commit comments