summaryrefslogtreecommitdiff
path: root/src/invidious/database/migrations/0004_create_users_table.cr
blob: a13ba15f0a7e797a1fbb4c6691bed4f76d808d24 (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
module Invidious::Database::Migrations
  class CreateUsersTable < Migration
    version 4

    def up(conn : DB::Connection)
      conn.exec <<-SQL
      CREATE TABLE IF NOT EXISTS public.users
      (
        updated timestamp with time zone,
        notifications text[],
        subscriptions text[],
        email text NOT NULL,
        preferences text,
        password text,
        token text,
        watched text[],
        feed_needs_update boolean,
        CONSTRAINT users_email_key UNIQUE (email)
      );
      SQL

      conn.exec <<-SQL
      GRANT ALL ON TABLE public.users TO current_user;
      SQL

      conn.exec <<-SQL
      CREATE UNIQUE INDEX IF NOT EXISTS email_unique_idx
        ON public.users
        USING btree
        (lower(email) COLLATE pg_catalog."default");
      SQL
    end
  end
end