Migration SQLs updated

This commit is contained in:
PB
2025-10-22 13:49:53 +02:00
parent 255d874a22
commit c5c10ff8fd
2 changed files with 50 additions and 7 deletions

View File

@@ -1,15 +1,57 @@
CREATE TABLE IF NOT EXISTS identity.users CREATE TABLE IF NOT EXISTS identity.users
( (
id uuid NOT NULL DEFAULT gen_random_uuid(), id uuid NOT NULL DEFAULT uuid_generate_v4(),
username character varying NOT NULL, username character varying NOT NULL,
"password" character varying NOT NULL, "password" character varying NOT NULL,
email character varying NOT NULL, email character varying NOT NULL,
created_at timestamp without time zone NOT NULL DEFAULT now(), created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone, updated_at timestamp without time zone,
PRIMARY KEY (id), PRIMARY KEY (id),
UNIQUE(username), UNIQUE (email),
UNIQUE(email) UNIQUE (username)
); );
ALTER TABLE IF EXISTS identity.users CREATE TABLE IF NOT EXISTS identity.roles
OWNER to postgres; (
id uuid NOT NULL DEFAULT uuid_generate_v4(),
name character varying(100) COLLATE pg_catalog."default" NOT NULL,
display_name character varying(200) COLLATE pg_catalog."default" NOT NULL,
created_at timestamp without time zone NOT NULL DEFAULT now(),
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS identity.users_roles
(
id uuid NOT NULL DEFAULT uuid_generate_v4(),
user_id uuid NOT NULL,
role_id uuid NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id)
REFERENCES identity.users (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID,
FOREIGN KEY (role_id)
REFERENCES identity.roles (id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
UNIQUE (user_id, role_id)
);
CREATE TABLE identity.url_access
(
id uuid NOT NULL DEFAULT uuid_generate_v4(),
roles json NOT NULL,
url character varying(255) NOT NULL,
service character varying(100) NOT NULL,
PRIMARY KEY (id),
UNIQUE (url, service)
);
ALTER TABLE IF EXISTS identity.users OWNER to egommerce;
ALTER TABLE IF EXISTS identity.roles OWNER to egommerce;
ALTER TABLE IF EXISTS identity.users_roles OWNER to egommerce;
ALTER TABLE IF EXISTS identity.url_access OWNER to egommerce;

View File

@@ -4,6 +4,7 @@ CREATE DATABASE egommerce;
GRANT ALL PRIVILEGES ON DATABASE egommerce TO egommerce; GRANT ALL PRIVILEGES ON DATABASE egommerce TO egommerce;
CREATE EXTENSION IF NOT EXISTS "pgcrypto"; CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE SCHEMA "identity-svc" -- CREATE SCHEMA "identity"
AUTHORIZATION postgres; -- AUTHORIZATION egommerce;