Renaming from tenant to organization

This commit is contained in:
Janus C. H. Knudsen 2025-02-14 20:14:01 +01:00
parent bf50563ab7
commit 087f8ce0e9
16 changed files with 129 additions and 243 deletions

View file

@ -9,7 +9,8 @@
"configuration": {
"host": "192.168.1.57",
"port": "5432",
"url": "jdbc:postgresql://192.168.1.57:5432/",
"database": "ptmain",
"url": "jdbc:postgresql://192.168.1.57:5432/ptmain",
"configurationType": "MANUAL",
"home": "postgresql_client",
"type": "dev",
@ -32,34 +33,9 @@
"postgresql.dd.tag.string": "false"
},
"auth-model": "native"
}
},
"postgres-jdbc-19484872d85-cd2a4a40116e706": {
"provider": "postgresql",
"driver": "postgres-jdbc",
"name": "UB-KK01-sathumper",
"configuration": {
"host": "192.168.1.57",
"port": "5432",
"database": "postgres",
"url": "jdbc:postgresql://192.168.1.57:5432/postgres",
"configurationType": "MANUAL",
"home": "postgresql_client",
"type": "dev",
"closeIdleConnection": true,
"provider-properties": {
"@dbeaver-show-non-default-db@": "true",
"@dbeaver-chosen-role@": "",
"@dbeaver-show-template-db@": "false",
"@dbeaver-show-unavailable-db@": "false",
"show-database-statistics": "false",
"@dbeaver-read-all-data-types-db@": "false",
"read-keys-with-columns": "false",
"@dbeaver-use-prepared-statements-db@": "false",
"postgresql.dd.plain.string": "false",
"postgresql.dd.tag.string": "false"
},
"auth-model": "native"
},
"custom-properties": {
"SQLEditor.outputPanel.autoShow": "false"
}
}
},

View file

@ -1 +1 @@
{"resources":{"Scripts/Script-11.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"}}}
{"resources":{"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01"}}}

View file

@ -6,6 +6,43 @@
"driver": "postgres-jdbc",
"name": "UB-KK01-postgres",
"save-password": true,
"configuration": {
"host": "192.168.1.57",
"port": "5432",
"database": "ptmain",
"url": "jdbc:postgresql://192.168.1.57:5432/ptmain",
"configurationType": "MANUAL",
"home": "postgresql_client",
"type": "dev",
"closeIdleConnection": true,
"properties": {
"connectTimeout": "20",
"loginTimeout": "20",
"escapeSyntaxCallMode": "callIfNoReturn"
},
"provider-properties": {
"@dbeaver-show-non-default-db@": "true",
"@dbeaver-chosen-role@": "",
"@dbeaver-show-template-db@": "false",
"@dbeaver-show-unavailable-db@": "false",
"show-database-statistics": "false",
"@dbeaver-read-all-data-types-db@": "false",
"read-keys-with-columns": "false",
"@dbeaver-use-prepared-statements-db@": "false",
"postgresql.dd.plain.string": "false",
"postgresql.dd.tag.string": "false"
},
"auth-model": "native"
},
"custom-properties": {
"SQLEditor.outputPanel.autoShow": "false"
}
},
"postgres-jdbc-1950174dc2f-6bd6c7100db1cc5c": {
"provider": "postgresql",
"driver": "postgres-jdbc",
"name": "UB-KK01-sathumper",
"save-password": true,
"configuration": {
"host": "192.168.1.57",
"port": "5432",

View file

@ -1 +1 @@
{"resources":{"Scripts/Script-11.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"sandbox"}}}
{"resources":{"Scripts/Script-1.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"},"Scripts/Script.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain","default-schema":"system"},"Scripts/SmartConfigSystem.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptdb01","default-schema":"public"},"Scripts/grant-privileges.sql":{"default-datasource":"postgres-jdbc-1948450a8b4-5fc9eec404e65c44","default-catalog":"ptmain"}}}

View file

View file

@ -1,144 +1,4 @@
drop schema "public"
show search_path;
set schema "ptmain";
CREATE SCHEMA if not exists ptmain;
GRANT USAGE, CREATE ON SCHEMA ptmain TO sathumper;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA ptmain TO sathumper;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ptmain TO sathumper;
ALTER DEFAULT PRIVILEGES IN SCHEMA ptmain
GRANT ALL PRIVILEGES ON TABLES TO sathumper;
-- Create schema if not exists
insert into
-- Create main configuration table
CREATE TABLE app_configuration (
id BIGSERIAL PRIMARY KEY,
key VARCHAR(255) NOT NULL,
value TEXT NOT NULL,
label VARCHAR(255),
content_type VARCHAR(255) DEFAULT 'text/plain',
valid_from TIMESTAMPTZ,
expires_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
etag UUID DEFAULT gen_random_uuid(),
CONSTRAINT app_configuration_key_unique UNIQUE (key, valid_from)
);
-- Create history table
CREATE TABLE app_configuration_history (
history_id BIGSERIAL PRIMARY KEY,
operation CHAR(1) NOT NULL, -- I = Insert, U = Update, D = Delete
changed_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
changed_by TEXT NOT NULL DEFAULT CURRENT_USER,
-- Original columns
id BIGINT NOT NULL,
key VARCHAR(255) NOT NULL,
value TEXT NOT NULL,
label VARCHAR(255),
content_type VARCHAR(255),
valid_from TIMESTAMPTZ,
expires_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL,
modified_at TIMESTAMPTZ NOT NULL,
etag UUID
);
-- Create function for updating modified_at
CREATE OR REPLACE FUNCTION update_modified_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.modified_at = CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- Create history tracking function
CREATE OR REPLACE FUNCTION track_configuration_history()
RETURNS TRIGGER AS $$
BEGIN
-- Indsæt historikpost baseret på operationstypen
IF TG_OP = 'INSERT' THEN
INSERT INTO app_configuration_history(
operation,
id, key, value, label, content_type, valid_from, expires_at,
created_at, modified_at, etag
)
VALUES (
'I',
NEW.id, NEW.key, NEW.value, NEW.label, NEW.content_type, NEW.valid_from,
NEW.expires_at, NEW.created_at, NEW.modified_at, NEW.etag
);
ELSIF TG_OP = 'UPDATE' OR TG_OP = 'DELETE' THEN
-- Brug OLD for både UPDATE og DELETE
INSERT INTO app_configuration_history(
operation,
id, key, value, label, content_type, valid_from, expires_at,
created_at, modified_at, etag
)
VALUES (
CASE
WHEN TG_OP = 'UPDATE' THEN 'U'
WHEN TG_OP = 'DELETE' THEN 'D'
END,
OLD.id, OLD.key, OLD.value, OLD.label, OLD.content_type, OLD.valid_from,
OLD.expires_at, OLD.created_at, OLD.modified_at, OLD.etag
);
END IF;
-- Returner NULL for AFTER-trigger
RETURN NULL;
EXCEPTION
WHEN others THEN
-- Log fejl og rejs undtagelse
RAISE EXCEPTION 'Fejl i track_configuration_history: %', SQLERRM;
END;
$$ LANGUAGE plpgsql;
-- Create triggers
CREATE TRIGGER trg_app_configuration_modified_at
BEFORE UPDATE ON app_configuration
FOR EACH ROW
EXECUTE FUNCTION update_modified_at();
CREATE TRIGGER trg_app_configuration_history
AFTER INSERT OR UPDATE OR DELETE ON app_configuration
FOR EACH ROW
EXECUTE FUNCTION track_configuration_history();
CREATE TRIGGER trg_app_configuration_notify
AFTER INSERT OR UPDATE ON app_configuration
FOR EACH ROW
EXECUTE FUNCTION notify_config_change();
-- Comments
COMMENT ON TABLE app_configuration IS 'Application configuration with temporal validity';
COMMENT ON TABLE app_configuration_history IS 'Historical changes to application configuration';
COMMENT ON COLUMN app_configuration_history.operation IS 'Type of operation: I=Insert, U=Update, D=Delete';
COMMENT ON COLUMN app_configuration_history.changed_at IS 'When the change occurred';
COMMENT ON COLUMN app_configuration_history.changed_by IS 'User who made the change';
DELETE from ptmain.app_configuration
-- Email templates configuration
INSERT INTO ptmain.app_configuration ("key",value,"label",content_type,valid_from,expires_at,created_at,modified_at,etag) VALUES
('Debug','true',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','f1348731-9396-4f1d-b40a-7fbd23a897d2'::uuid),
('Database:ConnectionString','"Server=db.example.com;Port=5432"',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','2aa0bc3e-fa24-449a-8f25-a76d9b4d535e'::uuid),
('Database:Timeout','30',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','d25ebb14-49f6-4e33-9ac7-a3253705d0fb'::uuid),
('Database:UseSSL','true',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','f4d52ec4-b723-4561-9b18-0e7a68b89a17'::uuid),
('Logging:FileOptions','{"Path": "/var/logs/app.log", "MaxSizeMB": 100, "RetentionDays": 7}',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','06c0891d-a860-4acc-917a-d0877f511c1b'::uuid),
('Features:Experimental','{"Enabled": true, "RolloutPercentage": 25, "AllowedUserGroups": ["beta"]}',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','0136fdef-51d9-4909-82ef-f72053ce6d6d'::uuid),
('API:Endpoints','"/api/users"',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','fe362b69-a486-48ad-9165-2e623e2e6f70'::uuid),
('API:Endpoints','"/api/products"',NULL,'text/plain',NULL,NULL,'2025-02-02 14:25:22.200058+01','2025-02-02 14:25:22.200058+01','c087e2d4-1f38-4814-b4dd-f30c463dc6d1'::uuid);
SELECT substring(datname, 5)::integer as dbnumber
FROM pg_database
WHERE datname LIKE 'ptdb%'
ORDER BY dbnumber DESC

View file

@ -4,14 +4,24 @@ CREATE ROLE sathumper WITH
LOGIN
PASSWORD '3911';
CREATE SCHEMA ptmain;
GRANT USAGE, CREATE ON SCHEMA ptmain TO sathumper;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA ptmain TO sathumper;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA ptmain TO sathumper;
CREATE SCHEMA "system";
GRANT USAGE, CREATE ON SCHEMA "system" TO sathumper;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "system" TO sathumper;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "system" TO sathumper;
ALTER DEFAULT PRIVILEGES IN SCHEMA ptmain
ALTER DEFAULT PRIVILEGES IN SCHEMA "system"
GRANT ALL PRIVILEGES ON TABLES TO sathumper;
SELECT usename, useconfig
FROM pg_user
WHERE useconfig IS NOT NULL
AND useconfig::text LIKE '%search_path%'
ALTER ROLE sathumper1 SET search_path='ss32'
CREATE USER fm WITH PASSWORD 'asd'
await _db.ExecuteAsync(sql);