update user_access table to match django
This commit is contained in:
1 parent
367533c02b
commit
76f4d0106a
1 file changed
+28
-4
@@ -3,7 +3,10 @@
|
|||||||
-- Source: ERD_dashboard.png (updated 2026-08-20)
|
-- Source: ERD_dashboard.png (updated 2026-08-20)
|
||||||
--
|
--
|
||||||
-- user_access.status: active | inactive | superadmin
|
-- user_access.status: active | inactive | superadmin
|
||||||
-- (Django syncs is_active/is_staff/is_superuser from status for auth internals)
|
-- (Django syncs is_active/is_staff/is_superuser from status on save:
|
||||||
|
-- inactive => all false; superadmin => is_active/is_superuser true,
|
||||||
|
-- is_staff false; active => is_active true, is_superuser false, is_staff
|
||||||
|
-- left untouched so operators can be marked staff)
|
||||||
-- user_access → sites → kandang → cycles
|
-- user_access → sites → kandang → cycles
|
||||||
-- cycles → flock (flock.cycle_id, required; cycles has no flock_id)
|
-- cycles → flock (flock.cycle_id, required; cycles has no flock_id)
|
||||||
-- flock → iot_panel
|
-- flock → iot_panel
|
||||||
@@ -14,18 +17,39 @@
|
|||||||
|
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
-- 1. User Access
|
-- 1. User Access
|
||||||
|
-- Django AbstractBaseUser + PermissionsMixin. `status` is the app's role
|
||||||
|
-- (active | inactive | superadmin); Django auth flags are synced from it on
|
||||||
|
-- save (is_staff stays untouched for active users, superadmin => is_staff
|
||||||
|
-- false, is_superuser true).
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
CREATE TABLE IF NOT EXISTS user_access (
|
CREATE TABLE IF NOT EXISTS user_access (
|
||||||
user_id SERIAL PRIMARY KEY,
|
user_id SERIAL PRIMARY KEY,
|
||||||
user_name VARCHAR(30) NOT NULL UNIQUE,
|
user_name VARCHAR(30) NOT NULL UNIQUE,
|
||||||
password_hash VARCHAR(255) NOT NULL,
|
password VARCHAR(128) NOT NULL,
|
||||||
status VARCHAR(30) NOT NULL,
|
last_login TIMESTAMP WITH TIME ZONE,
|
||||||
|
is_superuser BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
is_staff BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP
|
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
status VARCHAR(30) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_user_access_status ON user_access (status);
|
CREATE INDEX IF NOT EXISTS idx_user_access_status ON user_access (status);
|
||||||
|
|
||||||
|
-- Django PermissionsMixin many-to-many tables.
|
||||||
|
CREATE TABLE IF NOT EXISTS user_access_groups (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES user_access (user_id) ON DELETE CASCADE,
|
||||||
|
group_id INTEGER NOT NULL REFERENCES auth_group (id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS user_access_user_permissions (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
user_id INTEGER NOT NULL REFERENCES user_access (user_id) ON DELETE CASCADE,
|
||||||
|
permission_id INTEGER NOT NULL REFERENCES auth_permission (id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
-- 2. Sites
|
-- 2. Sites
|
||||||
-- -----------------------------------------------------------------------------
|
-- -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in new issue
Block a user