refactor: update init.sql to current schema
This commit is contained in:
@@ -1,3 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024-2026 OnixByte
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IMPORTANT NOTE ON DATABASE CREATION:
|
* IMPORTANT NOTE ON DATABASE CREATION:
|
||||||
* * If you intend to create the database using a user other than the one specified
|
* * If you intend to create the database using a user other than the one specified
|
||||||
@@ -89,27 +111,24 @@ CREATE TABLE users
|
|||||||
username VARCHAR(64) UNIQUE NOT NULL,
|
username VARCHAR(64) UNIQUE NOT NULL,
|
||||||
password VARCHAR(255),
|
password VARCHAR(255),
|
||||||
full_name VARCHAR(128) NOT NULL,
|
full_name VARCHAR(128) NOT NULL,
|
||||||
email VARCHAR(128) UNIQUE,
|
email VARCHAR(128) NULL UNIQUE,
|
||||||
region_code VARCHAR(10),
|
region_abbreviation VARCHAR(10) NULL,
|
||||||
phone_number VARCHAR(32),
|
phone_number VARCHAR(32) NULL,
|
||||||
avatar_url TEXT,
|
avatar_url TEXT,
|
||||||
status USER_STATUS NOT NULL DEFAULT 'ACTIVE',
|
status USER_STATUS NOT NULL DEFAULT 'ACTIVE',
|
||||||
department_id BIGINT REFERENCES departments (id),
|
department_id BIGINT REFERENCES departments (id),
|
||||||
position_id BIGINT REFERENCES positions (id),
|
position_id BIGINT REFERENCES positions (id),
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE (region_abbreviation, phone_number)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX users_username_index ON users (username);
|
CREATE INDEX users_username_index ON users (username);
|
||||||
|
|
||||||
--- Users Table Indexes ---
|
|
||||||
CREATE UNIQUE INDEX uidx_users_region_abbreviation_phone_number
|
|
||||||
ON users (region_abbreviation, phone_number);
|
|
||||||
|
|
||||||
--- Users Data Insertion ---
|
--- Users Data Insertion ---
|
||||||
-- NOTE: All phone numbers are generated by ChatGPT, they should not be connected any real person.
|
-- NOTE: All phone numbers are generated by ChatGPT, they should not be connected any real person.
|
||||||
INSERT INTO users(id, username, password, full_name, email, region_abbreviation, phone_number, avatar_url,
|
INSERT INTO users(id, username, password, full_name, email, region_abbreviation, phone_number,
|
||||||
department_id, position_id, created_at, updated_at)
|
avatar_url, department_id, position_id, created_at, updated_at)
|
||||||
VALUES (1, 'helix', null, 'Helix Admin', 'admin@helix.onixbyte.dev', 'GB', '7000000000',
|
VALUES (1, 'helix', null, 'Helix Admin', 'admin@helix.onixbyte.dev', 'GB', '7000000000',
|
||||||
'https://gravatar.com/avatar/6ef4c4033f6aa8e43d06bd5e462a6173cc2a960633473721a6f1289cd1b5146f',
|
'https://gravatar.com/avatar/6ef4c4033f6aa8e43d06bd5e462a6173cc2a960633473721a6f1289cd1b5146f',
|
||||||
1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
1, 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
|
||||||
@@ -310,14 +329,14 @@ CREATE TABLE menus
|
|||||||
status STATUS NOT NULL DEFAULT 'ACTIVE'::STATUS,
|
status STATUS NOT NULL DEFAULT 'ACTIVE'::STATUS,
|
||||||
authority_code VARCHAR(128) NULL DEFAULT NULL,
|
authority_code VARCHAR(128) NULL DEFAULT NULL,
|
||||||
icon VARCHAR(128) NULL DEFAULT NULL,
|
icon VARCHAR(128) NULL DEFAULT NULL,
|
||||||
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
update_time TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE INDEX menus_code_uindex ON menus (code);
|
CREATE UNIQUE INDEX menus_code_uindex ON menus (code);
|
||||||
|
|
||||||
INSERT INTO menus(id, name, parent_id, code, sort, path, is_external_link, is_visible, status,
|
INSERT INTO menus(id, name, parent_id, code, sort, path, is_external_link, is_visible, status,
|
||||||
authority_code, icon, create_time, update_time)
|
authority_code, icon, created_at, updated_at)
|
||||||
VALUES (1, '系统管理', NULL, 'system-manage', 99, NULL, FALSE, TRUE, 'ACTIVE'::STATUS, NULL, NULL,
|
VALUES (1, '系统管理', NULL, 'system-manage', 99, NULL, FALSE, TRUE, 'ACTIVE'::STATUS, NULL, NULL,
|
||||||
NOW(), NOW()),
|
NOW(), NOW()),
|
||||||
(2, '用户管理', 1, 'user-manage', 1, '/users', FALSE, TRUE, 'ACTIVE'::STATUS,
|
(2, '用户管理', 1, 'user-manage', 1, '/users', FALSE, TRUE, 'ACTIVE'::STATUS,
|
||||||
|
|||||||
Reference in New Issue
Block a user