2023-09-11 12:20:10 +07:00
|
|
|
CREATE TABLE users(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"email" varchar unique,
|
2023-09-12 12:52:01 +07:00
|
|
|
"username" varchar unique not null,
|
|
|
|
"password" varchar not null,
|
2023-09-11 12:20:10 +07:00
|
|
|
"avatar_picture" varchar,
|
|
|
|
"google_sign_in_payload" varchar,
|
|
|
|
"banned_at" timestamp,
|
|
|
|
"banned_until" timestamp,
|
|
|
|
"ban_reason" varchar,
|
2023-09-23 15:23:50 +07:00
|
|
|
"is_permaban" boolean default(false),
|
|
|
|
"is_admin" boolean default(false),
|
|
|
|
"is_critics" boolean default(false),
|
|
|
|
"is_verified" boolean default(false),
|
|
|
|
"is_active" boolean default(true),
|
2023-09-11 12:20:10 +07:00
|
|
|
"social_media" jsonb,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE client_ips(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"ipv4" varchar(15) not null,
|
|
|
|
"ipv6" varchar(40),
|
|
|
|
"banned_at" timestamp,
|
|
|
|
"banned_until" timestamp,
|
|
|
|
"reason" varchar,
|
|
|
|
"is_permaban" boolean,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TYPE user_reports_type as ENUM(
|
|
|
|
'comments',
|
|
|
|
'reviews',
|
|
|
|
'locations',
|
|
|
|
'users',
|
|
|
|
'stories'
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE user_reports(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"message" text not null,
|
|
|
|
"date" timestamp not null,
|
|
|
|
"report_target" integer not null,
|
|
|
|
"report_type" user_reports_type not null,
|
|
|
|
"submitted_by" integer references "users"("id") not null,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
2023-09-07 15:34:15 +07:00
|
|
|
|
|
|
|
CREATE TABLE regions(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"region_name" varchar,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE provinces(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"province_name" varchar,
|
|
|
|
"region_id" smallint references "regions"("id") not null,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE regencies(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"regency_name" varchar,
|
|
|
|
"province_id" smallint references "provinces"("id") not null,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE locations(
|
|
|
|
"id" serial primary key not null,
|
2023-09-12 12:52:01 +07:00
|
|
|
"address" varchar not null,
|
|
|
|
"name" varchar not null,
|
2023-09-07 15:34:15 +07:00
|
|
|
"google_maps_link" varchar,
|
|
|
|
"submitted_by" integer references "users"("id") not null,
|
|
|
|
"total_visited" integer,
|
2023-09-13 21:42:04 +07:00
|
|
|
"thumbnail" varchar,
|
2023-09-07 15:34:15 +07:00
|
|
|
"regency_id" smallint references "regencies"("id") not null,
|
|
|
|
"is_deleted" boolean,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE tags (
|
2023-09-14 22:50:26 +07:00
|
|
|
"id" serial primary key not null,
|
|
|
|
"name" varchar(50) not null,
|
2023-09-17 16:30:19 +07:00
|
|
|
"submitted_by" integer references "users"("id") not null,
|
2023-09-20 13:37:14 +07:00
|
|
|
"target_id" integer not null, -- location_id, story_id
|
|
|
|
"tags_type" varchar(20) not null, -- locations, stories
|
|
|
|
"approved_by" integer references "users"("id")
|
2023-09-07 15:34:15 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE location_images (
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"url" varchar not null,
|
|
|
|
"location_id" integer references "locations"("id") not null,
|
|
|
|
"uploaded_by" integer references "users"("id"),
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE reviews (
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"submitted_by" integer references "users"("id") not null,
|
|
|
|
"comments" text not null,
|
|
|
|
"score" smallint not null,
|
2023-09-14 22:50:26 +07:00
|
|
|
"is_from_critic" boolean not null,
|
2023-09-07 15:34:15 +07:00
|
|
|
"is_hided" boolean, -- if comments violate TOS just hide the reviews
|
|
|
|
"location_id" integer references "locations"("id") not null,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
2023-09-11 12:20:10 +07:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TYPE comment_type AS ENUM(
|
|
|
|
'stories',
|
|
|
|
'news',
|
|
|
|
'reviews'
|
|
|
|
);
|
2023-09-07 15:34:15 +07:00
|
|
|
|
2023-09-11 12:20:10 +07:00
|
|
|
CREATE TABLE comments(
|
|
|
|
"id" serial primary key not null,
|
|
|
|
"submitted_by" integer not null,
|
|
|
|
"comment_on" integer not null,
|
|
|
|
"comment_type" comment_type not null,
|
|
|
|
"reply_to" integer,
|
|
|
|
"is_hide" boolean,
|
|
|
|
"created_at" timestamp default(now()),
|
|
|
|
"updated_at" timestamp default(now())
|
2023-09-07 15:34:15 +07:00
|
|
|
);
|