Add multi-tenant system

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-02-25 22:52:06 +01:00
parent 29ce55e89c
commit 0c176674a0
35 changed files with 1254 additions and 686 deletions

View File

@@ -0,0 +1,11 @@
CREATE TABLE usrmgr_user_organizations (
user_id TEXT REFERENCES usrmgr_users(id) NOT NULL,
organization_id TEXT REFERENCES organizations(id) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
PRIMARY KEY (user_id, organization_id)
);
INSERT INTO usrmgr_user_organizations (user_id, organization_id, created_at)
SELECT id, organization_id, NOW()
FROM usrmgr_users
WHERE organization_id IS NOT NULL;

View File

@@ -0,0 +1 @@
ALTER TABLE usrmgr_users ADD COLUMN fullname TEXT;

View File

@@ -0,0 +1 @@
ALTER TABLE usrmgr_users ALTER COLUMN fullname SET NOT NULL;

View File

@@ -29,6 +29,7 @@ type (
ID gid.GID
EmailAddress string
HashedPassword []byte
FullName string
OrganizationID gid.GID
CreatedAt time.Time
UpdatedAt time.Time
@@ -44,6 +45,7 @@ func (u *User) scan(r pgx.Row) error {
&u.ID,
&u.EmailAddress,
&u.HashedPassword,
&u.FullName,
&u.OrganizationID,
&u.CreatedAt,
&u.UpdatedAt,
@@ -60,6 +62,7 @@ SELECT
id,
email_address,
hashed_password,
fullname,
organization_id,
created_at,
updated_at
@@ -94,6 +97,7 @@ SELECT
id,
email_address,
hashed_password,
fullname,
organization_id,
created_at,
updated_at
@@ -124,11 +128,12 @@ func (u *User) Insert(
) error {
q := `
INSERT INTO
usrmgr_users (id, email_address, hashed_password, organization_id, created_at, updated_at)
usrmgr_users (id, email_address, hashed_password, fullname, organization_id, created_at, updated_at)
VALUES (
@user_id,
@email_address,
@hashed_password,
@fullname,
@organization_id,
@created_at,
@updated_at
@@ -139,6 +144,7 @@ VALUES (
"user_id": u.ID,
"email_address": u.EmailAddress,
"hashed_password": u.HashedPassword,
"fullname": u.FullName,
"organization_id": "AZSfP_xAcAC5IAAAAAAltA",
"created_at": u.CreatedAt,
"updated_at": u.UpdatedAt,