aboutsummaryrefslogtreecommitdiff
path: root/server/migrations/1.sql
blob: d7c300e2f96142778604fb01f100b2cf6d69fc43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
CREATE TABLE IF NOT EXISTS "user" (
  "id" INTEGER PRIMARY KEY,
  "creation" TIMESTAMP NOT NULL,
  "email" VARCHAR NOT NULL,
  "name" VARCHAR NOT NULL,
  CONSTRAINT "uniq_user_email" UNIQUE ("email"),
  CONSTRAINT "uniq_user_name" UNIQUE ("name")
);

CREATE TABLE IF NOT EXISTS "job" (
  "id" INTEGER PRIMARY KEY,
  "kind" VARCHAR NOT NULL,
  "last_execution" TIMESTAMP NULL,
  "last_check" TIMESTAMP NULL,
  CONSTRAINT "uniq_job_kind" UNIQUE ("kind")
);

CREATE TABLE IF NOT EXISTS "sign_in"(
  "id" INTEGER PRIMARY KEY,
  "token" VARCHAR NOT NULL,
  "creation" TIMESTAMP NOT NULL,
  "email" VARCHAR NOT NULL,
  "is_used" BOOLEAN NOT NULL,
  CONSTRAINT "uniq_sign_in_token" UNIQUE ("token")
);

CREATE TABLE IF NOT EXISTS "payment"(
  "id" INTEGER PRIMARY KEY,
  "user_id" INTEGER NOT NULL REFERENCES "user",
  "name" VARCHAR NOT NULL,
  "cost" INTEGER NOT NULL,
  "date" DATE NOT NULL,
  "frequency" VARCHAR NOT NULL,
  "created_at" TIMESTAMP NOT NULL,
  "edited_at" TIMESTAMP NULL,
  "deleted_at" TIMESTAMP NULL
);

CREATE TABLE IF NOT EXISTS "income"(
  "id" INTEGER PRIMARY KEY,
  "user_id" INTEGER NOT NULL REFERENCES "user",
  "date" DATE NOT NULL,
  "amount" INTEGERNOT NULL,
  "created_at" TIMESTAMP NOT NULL,
  "edited_at" TIMESTAMP NULL,
  "deleted_at" TIMESTAMP NULL
);

CREATE TABLE IF NOT EXISTS "category"(
  "id" INTEGER PRIMARY KEY,
  "name" VARCHAR NOT NULL,
  "color" VARCHAR NOT NULL,
  "created_at" TIMESTAMP NOT NULL,
  "edited_at" TIMESTAMP NULL,
  "deleted_at" TIMESTAMP NULL
);

CREATE TABLE IF NOT EXISTS "payment_category"(
  "id" INTEGER PRIMARY KEY,
  "name" VARCHAR NOT NULL,
  "category" INTEGER NOT NULL REFERENCES "category",
  "created_at" TIMESTAMP NOT NULL,
  "edited_at" TIMESTAMP NULL,
  CONSTRAINT "uniq_payment_category_name" UNIQUE ("name")
);