summaryrefslogtreecommitdiff
path: root/migrations/20250819.php
blob: 061b59ca24cefac322fcae89d8fce5bee96a072b (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
<?php

use App\Database;

Database::getInstance()->query(<<<SQL
  create table if not exists "migrations" (
    "id" bigserial primary key,
    "name" varchar(64) not null
  );
SQL);

Database::getInstance()->query(<<<SQL
  create table if not exists "users" (
    "id" varchar(255) primary key,
    "password" varchar(255),

    "name" varchar(255),
    "is_deactivated" bool
  );
SQL);

Database::getInstance()->query(<<<SQL
  create table if not exists "devices" (
    "id" varchar(255) not null,
    "name" varchar(255) not null,

    "user_id" varchar(255) references users(id) not null,

    primary key (user_id, id)
  );
SQL);

Database::getInstance()->query(<<<SQL
  create table if not exists "tokens" (
    "id" bigserial primary key,

    "access_token" varchar(255) not null,
    "refresh_token" varchar(255) not null,

    "expires_at" timestamptz(3) not null,

    "user_id" varchar(255) not null,
    "device_id" varchar(255),

    "created_at" timestamptz(3) not null,

    foreign key (user_id, device_id) references devices(user_id, id)
  );
SQL);