Files
online-backend/db/migrations/20260702125108_init.up.sql
GuwandykA 77bc4025d3 Add branch_user table and branch-user assignment endpoints
Introduces a branch_user join table linking branches to users, plus
create/delete API endpoints under the auth module for managing branch
assignments. The create response includes the branch's localized name
via a join. Regenerated swagger docs to include the new endpoints.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-08 15:02:05 +05:00

121 lines
5.3 KiB
SQL

CREATE TABLE IF NOT EXISTS users (
"id" bigserial primary key,
"email" character varying(250) NOT NULL DEFAULT '',
"name" character varying(250) NOT NULL DEFAULT '',
"password" character varying(250) NOT NULL DEFAULT '',
"first_name" character varying(250) NOT NULL DEFAULT '',
"last_name" character varying(250) NOT NULL DEFAULT '',
"username" character varying(250) NOT NULL DEFAULT '',
"phone" character varying(250) NOT NULL DEFAULT '',
"light_mode" integer DEFAULT 1 NOT NULL,
"role" character varying(250) NOT NULL DEFAULT 'user',
"active" boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
insert into users(
phone, password, name, email, role
) values (
'61531216',
'$2a$12$8ZbKmoSwna4CASQptM2/SubwvsBUR1YhABULd.2/QJB.13Wi2v55m',
'Admin',
'admin@admin.com',
'admin'
);
CREATE TABLE IF NOT EXISTS provinces (
id bigserial PRIMARY KEY,
name json NOT NULL DEFAULT '{}'::json,
region json NOT NULL DEFAULT '{}'::json,
active boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS branches (
id bigserial PRIMARY KEY,
unique_code character varying(255) UNIQUE,
name json NOT NULL DEFAULT '{}'::json,
address json NOT NULL DEFAULT '{}'::json,
region character varying(2) NOT NULL DEFAULT '',
province_id bigint REFERENCES provinces(id) ON DELETE SET NULL,
phone_numbers json NOT NULL DEFAULT '[]'::json,
billing_username character varying(255) NOT NULL DEFAULT '',
billing_password character varying(255) NOT NULL DEFAULT '',
billing_swift_username character varying(255) NOT NULL DEFAULT '',
billing_swift_password character varying(255) NOT NULL DEFAULT '',
billing_visa_master_username character varying(255) NOT NULL DEFAULT '',
billing_visa_master_password character varying(255) NOT NULL DEFAULT '',
billing_sber_username character varying(255) NOT NULL DEFAULT '',
billing_sber_password character varying(255) NOT NULL DEFAULT '',
active boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS card_types (
id bigserial PRIMARY KEY,
name json NOT NULL DEFAULT '{}'::json,
price character varying(255) NOT NULL DEFAULT '',
notes character varying(255) NOT NULL DEFAULT '',
active boolean NOT NULL DEFAULT true,
"updated_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
"created_at" TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS card_states (
id bigserial PRIMARY KEY,
name json NOT NULL DEFAULT '{}'::json,
price character varying(255) NOT NULL DEFAULT '',
notes character varying(255) NOT NULL DEFAULT '',
active boolean NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS loan_types (
id bigserial PRIMARY KEY,
name json NOT NULL DEFAULT '{}'::json,
tax numeric(12, 2) NOT NULL DEFAULT 0,
maturity character varying(250) NOT NULL DEFAULT '',
notes json NOT NULL DEFAULT '{}'::json,
active boolean NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS loan_order_required_docs (
id bigserial PRIMARY KEY,
name text NOT NULL DEFAULT '',
value text NOT NULL DEFAULT '',
active boolean NOT NULL DEFAULT true,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS roles (
id bigserial PRIMARY KEY,
code character varying(255) NOT NULL DEFAULT '',
name character varying(255) NOT NULL,
guard_name character varying(255) NOT NULL,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS permissions (
id bigserial PRIMARY KEY,
code character varying(255) NOT NULL DEFAULT '',
name character varying(255) NOT NULL,
guard_name character varying(255) NOT NULL,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);
CREATE TABLE IF NOT EXISTS branch_user (
id bigserial PRIMARY KEY,
branch_id bigint REFERENCES branches(id) ON DELETE CASCADE,
user_id bigint REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL,
updated_at TIMESTAMP DEFAULT (CURRENT_TIMESTAMP AT TIME ZONE 'UTC') NOT NULL
);