From c5c10ff8fdcaa0585d479b580bfcc89a3854fb79 Mon Sep 17 00:00:00 2001 From: Piotr Biernat Date: Wed, 22 Oct 2025 13:49:53 +0200 Subject: [PATCH] Migration SQLs updated --- .../0001_create_base_tables.up.sql | 52 +++++++++++++++++-- deploy/db_migrations/init/init.sql | 5 +- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql b/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql index 46afdf7..6cca0ef 100644 --- a/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql +++ b/deploy/db_migrations/identity-svc/0001_create_base_tables.up.sql @@ -1,15 +1,57 @@ 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, "password" character varying NOT NULL, email character varying NOT NULL, created_at timestamp without time zone NOT NULL DEFAULT now(), updated_at timestamp without time zone, PRIMARY KEY (id), - UNIQUE(username), - UNIQUE(email) + UNIQUE (email), + UNIQUE (username) ); -ALTER TABLE IF EXISTS identity.users - OWNER to postgres; +CREATE TABLE IF NOT EXISTS identity.roles +( + 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; diff --git a/deploy/db_migrations/init/init.sql b/deploy/db_migrations/init/init.sql index 2496097..ee6f9f3 100644 --- a/deploy/db_migrations/init/init.sql +++ b/deploy/db_migrations/init/init.sql @@ -4,6 +4,7 @@ CREATE DATABASE egommerce; GRANT ALL PRIVILEGES ON DATABASE egommerce TO egommerce; CREATE EXTENSION IF NOT EXISTS "pgcrypto"; +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -CREATE SCHEMA "identity-svc" - AUTHORIZATION postgres; +-- CREATE SCHEMA "identity" +-- AUTHORIZATION egommerce;