001-identity-init.xml
4.15 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.27.xsd">
<!--
pbc-identity initial schema.
Owns: identity__user, identity__role, identity__user_role.
vibe_erp is single-tenant per instance: one running process serves
exactly one company against an isolated database. There are no
tenant_id columns and no Row-Level Security policies on these
tables — customer isolation happens at the deployment level.
Conventions enforced for every business table in vibe_erp:
• UUID primary key
• Audit columns: created_at, created_by, updated_at, updated_by
• Optimistic-locking version column
• ext jsonb NOT NULL DEFAULT '{}' for key-user custom fields
• GIN index on ext for fast custom-field queries
-->
<changeSet id="identity-init-001" author="vibe_erp">
<comment>Create identity__user table</comment>
<sql>
CREATE TABLE identity__user (
id uuid PRIMARY KEY,
username varchar(128) NOT NULL,
display_name varchar(256) NOT NULL,
email varchar(320),
enabled boolean NOT NULL DEFAULT true,
ext jsonb NOT NULL DEFAULT '{}'::jsonb,
created_at timestamptz NOT NULL,
created_by varchar(128) NOT NULL,
updated_at timestamptz NOT NULL,
updated_by varchar(128) NOT NULL,
version bigint NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX identity__user_username_uk
ON identity__user (username);
CREATE INDEX identity__user_ext_gin
ON identity__user USING GIN (ext jsonb_path_ops);
</sql>
<rollback>
DROP TABLE identity__user;
</rollback>
</changeSet>
<changeSet id="identity-init-002" author="vibe_erp">
<comment>Create identity__role table</comment>
<sql>
CREATE TABLE identity__role (
id uuid PRIMARY KEY,
code varchar(64) NOT NULL,
name varchar(256) NOT NULL,
description text,
ext jsonb NOT NULL DEFAULT '{}'::jsonb,
created_at timestamptz NOT NULL,
created_by varchar(128) NOT NULL,
updated_at timestamptz NOT NULL,
updated_by varchar(128) NOT NULL,
version bigint NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX identity__role_code_uk
ON identity__role (code);
CREATE INDEX identity__role_ext_gin
ON identity__role USING GIN (ext jsonb_path_ops);
</sql>
<rollback>
DROP TABLE identity__role;
</rollback>
</changeSet>
<changeSet id="identity-init-003" author="vibe_erp">
<comment>Create identity__user_role join table</comment>
<sql>
CREATE TABLE identity__user_role (
id uuid PRIMARY KEY,
user_id uuid NOT NULL REFERENCES identity__user(id) ON DELETE CASCADE,
role_id uuid NOT NULL REFERENCES identity__role(id) ON DELETE CASCADE,
created_at timestamptz NOT NULL,
created_by varchar(128) NOT NULL,
updated_at timestamptz NOT NULL,
updated_by varchar(128) NOT NULL,
version bigint NOT NULL DEFAULT 0
);
CREATE UNIQUE INDEX identity__user_role_uk
ON identity__user_role (user_id, role_id);
</sql>
<rollback>
DROP TABLE identity__user_role;
</rollback>
</changeSet>
</databaseChangeLog>