/
create_users_table.sql
42 lines (29 loc) · 1.12 KB
/
create_users_table.sql
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
create table users
(
id integer not null
constraint users_pk
primary key,
email varchar(255) not null,
first_name varchar(255) not null,
last_name varchar(255) not null,
password varchar(60) not null,
created_at timestamp default now() not null,
updated_at timestamp default now() not null
);
comment on table users is 'Table of users';
comment on column users.id is 'ID of user';
comment on column users.email is 'User''s email address';
comment on column users.first_name is 'User''s first name';
comment on column users.last_name is 'User''s last name';
comment on column users.password is 'Password hash';
comment on column users.created_at is 'Created At';
comment on column users.updated_at is 'Updated At';
alter table users
owner to postgres;
CREATE SEQUENCE user_id_seq START WITH 1;
ALTER TABLE users
ALTER COLUMN id SET DEFAULT nextval('user_id_seq');
create unique index users_email_index
on public.users (email);
alter table public.users
add user_active integer default 0 not null;