tighten the api

This commit is contained in:
gowthaman.b
2023-11-11 16:13:59 +05:30
parent 31388bae59
commit f35851d339
15 changed files with 247 additions and 143 deletions

View File

@@ -0,0 +1,2 @@
insert into tenant_model(name, domain, created_by, modified_by) values ('compegence', 'https://www.compegence.com', 'system', 'system');
insert into entity_model(name, tenant_id, created_by, modified_by) values ('vehicle', 'compegence', 'system', 'system');

View File

@@ -2,17 +2,17 @@
create table audit_log (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer not null,
required_approval_levels integer not null,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
deleted boolean default false not null,
version integer not null,
created_at timestamp not null,
modified_at timestamp not null,
tenant_id varchar(255) not null,
version integer default 1 not null,
created_at timestamp default 'now()' not null,
modified_at timestamp default 'now()' not null,
deleted_by varchar(255),
approval_status varchar(8) not null,
tags varchar[] not null,
comments jsonb not null,
approval_status varchar(8) default 'APPROVED' not null,
tags text[] default '{}'::text[] not null,
comments jsonb default '[]'::jsonb not null,
tenant_id varchar(255) not null,
audit_type varchar(7) not null,
entity varchar(255) not null,
unique_identifier varchar(255) not null,
@@ -28,17 +28,17 @@ create table audit_log (
create table data_model (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer not null,
required_approval_levels integer not null,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
deleted boolean default false not null,
version integer not null,
created_at timestamp not null,
modified_at timestamp not null,
tenant_id varchar(255) not null,
version integer default 1 not null,
created_at timestamp default 'now()' not null,
modified_at timestamp default 'now()' not null,
deleted_by varchar(255),
approval_status varchar(8) not null,
tags varchar[] not null,
comments jsonb not null,
approval_status varchar(8) default 'APPROVED' not null,
tags text[] default '{}'::text[] not null,
comments jsonb default '[]'::jsonb not null,
tenant_id varchar(255) not null,
unique_identifier varchar(255) not null,
entity_name varchar(255) not null,
data jsonb not null,
@@ -52,26 +52,26 @@ create table data_model (
create table entity_model (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer not null,
required_approval_levels integer not null,
approval_levels integer not null,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
approval_levels integer default 0 not null,
deleted boolean default false not null,
version integer not null,
created_at timestamp not null,
modified_at timestamp not null,
tenant_id varchar(255) not null,
version integer default 1 not null,
created_at timestamp default 'now()' not null,
modified_at timestamp default 'now()' not null,
deleted_by varchar(255),
approval_status varchar(8) not null,
tags varchar[] not null,
comments jsonb not null,
approval_status varchar(8) default 'APPROVED' not null,
tags text[] default '{}'::text[] not null,
comments jsonb default '[]'::jsonb not null,
tenant_id varchar(255) not null,
name varchar(255) not null,
pre_save_script varchar(255) not null,
post_save_script varchar(255) not null,
actions varchar[] not null,
allowed_fields varchar[] not null,
allowed_field_types jsonb not null,
audit_log_fields varchar[] not null,
preferences jsonb not null,
pre_save_script varchar(255),
post_save_script varchar(255),
actions text[] default '{}'::text[] not null,
allowed_fields text[] default '{}'::text[] not null,
allowed_field_types jsonb default '{}'::jsonb not null,
audit_log_fields text[] default '{}'::text[] not null,
preferences jsonb default '{}'::jsonb not null,
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_entity_model_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
@@ -82,17 +82,17 @@ create table entity_model (
create table job_model (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer not null,
required_approval_levels integer not null,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
deleted boolean default false not null,
version integer not null,
created_at timestamp not null,
modified_at timestamp not null,
tenant_id varchar(255) not null,
version integer default 1 not null,
created_at timestamp default 'now()' not null,
modified_at timestamp default 'now()' not null,
deleted_by varchar(255),
approval_status varchar(8) not null,
tags varchar[] not null,
comments jsonb not null,
approval_status varchar(8) default 'APPROVED' not null,
tags text[] default '{}'::text[] not null,
comments jsonb default '[]'::jsonb not null,
tenant_id varchar(255) not null,
job_name varchar(255) not null,
job_type varchar(6) not null,
job_path varchar(255) not null,
@@ -111,28 +111,31 @@ create table job_model (
create table tenant_model (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer not null,
required_approval_levels integer not null,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
deleted boolean default false not null,
version integer not null,
created_at timestamp not null,
modified_at timestamp not null,
tenant_id varchar(255) not null,
version integer default 1 not null,
created_at timestamp default 'now()' not null,
modified_at timestamp default 'now()' not null,
deleted_by varchar(255),
approval_status varchar(8) not null,
tags varchar[] not null,
comments jsonb not null,
approval_status varchar(8) default 'APPROVED' not null,
tags text[] default '{}'::text[] not null,
comments jsonb default '[]'::jsonb not null,
name varchar(255) not null,
domain varchar(255) not null,
preferences jsonb not null,
preferences jsonb default '{}'::jsonb not null,
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_tenant_model_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
constraint uq_tenant_model_name unique (name),
constraint pk_tenant_model primary key (sys_pk)
);
-- foreign keys and indices
create index if not exists ix_audit_log_audit_type_entity_unique_identifier_tenant_i_1 on audit_log (audit_type,entity,unique_identifier,tenant_id,created_by);
create index audit_log_values_idx on audit_log using GIN (data) ;
create index audit_log_changes_idx on audit_log using GIN (changes) ;
create index audit_log_values_idx on audit_log using GIN (data);
create index audit_log_changes_idx on audit_log using GIN (changes);
create index data_jsonb_idx on data_model using GIN (data) ;
ALTER TABLE data_model ADD FOREIGN KEY(tenant_id) REFERENCES tenant_model(name);
ALTER TABLE data_model ADD FOREIGN KEY(entity_name) REFERENCES entity_model(name);

View File

@@ -3,84 +3,84 @@
<changeSet type="apply">
<createTable name="audit_log" pkName="pk_audit_log">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<column name="current_approval_level" type="integer" notnull="true"/>
<column name="required_approval_levels" type="integer" notnull="true"/>
<column name="approval_status" type="varchar(8)" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_audit_log_approval_status"/>
<column name="tags" type="varchar[]" notnull="true"/>
<column name="comments" type="jsonb" notnull="true"/>
<column name="current_approval_level" type="integer" defaultValue="0" notnull="true"/>
<column name="required_approval_levels" type="integer" defaultValue="0" notnull="true"/>
<column name="approval_status" type="varchar(8)" defaultValue="'APPROVED'" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_audit_log_approval_status"/>
<column name="tags" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="comments" type="jsonb" defaultValue="'[]'" notnull="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="audit_type" type="varchar(7)" notnull="true" checkConstraint="check ( audit_type in ('CREATE','UPDATE','DELETE','VIEW','APPROVE','REJECT'))" checkConstraintName="ck_audit_log_audit_type"/>
<column name="entity" type="varchar" notnull="true"/>
<column name="unique_identifier" type="varchar" notnull="true"/>
<column name="data" type="jsonb" notnull="true"/>
<column name="changes" type="jsonb" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
<column name="version" type="integer" notnull="true"/>
<column name="created_at" type="localdatetime" notnull="true"/>
<column name="modified_at" type="localdatetime" notnull="true"/>
<column name="version" type="integer" defaultValue="1" notnull="true"/>
<column name="created_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="modified_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="created_by" type="varchar" notnull="true"/>
<column name="modified_by" type="varchar" notnull="true"/>
</createTable>
<createTable name="data_model" pkName="pk_data_model">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<column name="current_approval_level" type="integer" notnull="true"/>
<column name="required_approval_levels" type="integer" notnull="true"/>
<column name="approval_status" type="varchar(8)" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_data_model_approval_status"/>
<column name="tags" type="varchar[]" notnull="true"/>
<column name="comments" type="jsonb" notnull="true"/>
<column name="current_approval_level" type="integer" defaultValue="0" notnull="true"/>
<column name="required_approval_levels" type="integer" defaultValue="0" notnull="true"/>
<column name="approval_status" type="varchar(8)" defaultValue="'APPROVED'" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_data_model_approval_status"/>
<column name="tags" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="comments" type="jsonb" defaultValue="'[]'" notnull="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="unique_identifier" type="varchar" notnull="true"/>
<column name="entity_name" type="varchar" notnull="true"/>
<column name="data" type="jsonb" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
<column name="version" type="integer" notnull="true"/>
<column name="created_at" type="localdatetime" notnull="true"/>
<column name="modified_at" type="localdatetime" notnull="true"/>
<column name="version" type="integer" defaultValue="1" notnull="true"/>
<column name="created_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="modified_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="created_by" type="varchar" notnull="true"/>
<column name="modified_by" type="varchar" notnull="true"/>
<uniqueConstraint name="entity_unique_id" columnNames="entity_name,unique_identifier,tenant_id" oneToOne="false" nullableColumns=""/>
</createTable>
<createTable name="entity_model" pkName="pk_entity_model">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<column name="current_approval_level" type="integer" notnull="true"/>
<column name="required_approval_levels" type="integer" notnull="true"/>
<column name="approval_status" type="varchar(8)" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_entity_model_approval_status"/>
<column name="tags" type="varchar[]" notnull="true"/>
<column name="comments" type="jsonb" notnull="true"/>
<column name="current_approval_level" type="integer" defaultValue="0" notnull="true"/>
<column name="required_approval_levels" type="integer" defaultValue="0" notnull="true"/>
<column name="approval_status" type="varchar(8)" defaultValue="'APPROVED'" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_entity_model_approval_status"/>
<column name="tags" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="comments" type="jsonb" defaultValue="'[]'" notnull="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="name" type="varchar" notnull="true"/>
<column name="pre_save_script" type="varchar" notnull="true"/>
<column name="post_save_script" type="varchar" notnull="true"/>
<column name="actions" type="varchar[]" notnull="true"/>
<column name="allowed_fields" type="varchar[]" notnull="true"/>
<column name="allowed_field_types" type="jsonb" notnull="true"/>
<column name="audit_log_fields" type="varchar[]" notnull="true"/>
<column name="preferences" type="jsonb" notnull="true"/>
<column name="approval_levels" type="integer" notnull="true"/>
<column name="pre_save_script" type="varchar"/>
<column name="post_save_script" type="varchar"/>
<column name="actions" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="allowed_fields" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="allowed_field_types" type="jsonb" defaultValue="'{}'" notnull="true"/>
<column name="audit_log_fields" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="preferences" type="jsonb" defaultValue="'{}'" notnull="true"/>
<column name="approval_levels" type="integer" defaultValue="0" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
<column name="version" type="integer" notnull="true"/>
<column name="created_at" type="localdatetime" notnull="true"/>
<column name="modified_at" type="localdatetime" notnull="true"/>
<column name="version" type="integer" defaultValue="1" notnull="true"/>
<column name="created_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="modified_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="created_by" type="varchar" notnull="true"/>
<column name="modified_by" type="varchar" notnull="true"/>
<uniqueConstraint name="uq_entity_model_name" columnNames="name" oneToOne="false" nullableColumns=""/>
</createTable>
<createTable name="job_model" pkName="pk_job_model">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<column name="current_approval_level" type="integer" notnull="true"/>
<column name="required_approval_levels" type="integer" notnull="true"/>
<column name="approval_status" type="varchar(8)" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_job_model_approval_status"/>
<column name="tags" type="varchar[]" notnull="true"/>
<column name="comments" type="jsonb" notnull="true"/>
<column name="current_approval_level" type="integer" defaultValue="0" notnull="true"/>
<column name="required_approval_levels" type="integer" defaultValue="0" notnull="true"/>
<column name="approval_status" type="varchar(8)" defaultValue="'APPROVED'" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_job_model_approval_status"/>
<column name="tags" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="comments" type="jsonb" defaultValue="'[]'" notnull="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="job_name" type="varchar" notnull="true"/>
<column name="job_type" type="varchar(6)" notnull="true" checkConstraint="check ( job_type in ('SCRIPT','DB'))" checkConstraintName="ck_job_model_job_type"/>
<column name="job_path" type="varchar" notnull="true"/>
@@ -88,36 +88,36 @@
<column name="job_frequency_type" type="varchar(8)" notnull="true" checkConstraint="check ( job_frequency_type in ('SPECIFIC','EVERY','CRON'))" checkConstraintName="ck_job_model_job_frequency_type"/>
<column name="frequency" type="varchar" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
<column name="version" type="integer" notnull="true"/>
<column name="created_at" type="localdatetime" notnull="true"/>
<column name="modified_at" type="localdatetime" notnull="true"/>
<column name="version" type="integer" defaultValue="1" notnull="true"/>
<column name="created_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="modified_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="created_by" type="varchar" notnull="true"/>
<column name="modified_by" type="varchar" notnull="true"/>
<uniqueConstraint name="uq_job_model_job_name" columnNames="job_name" oneToOne="false" nullableColumns=""/>
</createTable>
<createTable name="tenant_model" pkName="pk_tenant_model">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="tenant_id" type="varchar" notnull="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<column name="current_approval_level" type="integer" notnull="true"/>
<column name="required_approval_levels" type="integer" notnull="true"/>
<column name="approval_status" type="varchar(8)" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_tenant_model_approval_status"/>
<column name="tags" type="varchar[]" notnull="true"/>
<column name="comments" type="jsonb" notnull="true"/>
<column name="current_approval_level" type="integer" defaultValue="0" notnull="true"/>
<column name="required_approval_levels" type="integer" defaultValue="0" notnull="true"/>
<column name="approval_status" type="varchar(8)" defaultValue="'APPROVED'" notnull="true" checkConstraint="check ( approval_status in ('PENDING','APPROVED','REJECTED'))" checkConstraintName="ck_tenant_model_approval_status"/>
<column name="tags" type="varchar[]" defaultValue="'{}'" notnull="true"/>
<column name="comments" type="jsonb" defaultValue="'[]'" notnull="true"/>
<column name="name" type="varchar" notnull="true"/>
<column name="domain" type="varchar" notnull="true"/>
<column name="preferences" type="jsonb" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" notnull="true"/>
<column name="version" type="integer" notnull="true"/>
<column name="created_at" type="localdatetime" notnull="true"/>
<column name="modified_at" type="localdatetime" notnull="true"/>
<column name="version" type="integer" defaultValue="1" notnull="true"/>
<column name="created_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="modified_at" type="localdatetime" defaultValue="'now()'" notnull="true"/>
<column name="created_by" type="varchar" notnull="true"/>
<column name="modified_by" type="varchar" notnull="true"/>
<uniqueConstraint name="uq_tenant_model_name" columnNames="name" oneToOne="false" nullableColumns=""/>
</createTable>
<createIndex indexName="ix_audit_log_audit_type_entity_unique_identifier_tenant_i_1" tableName="audit_log" columns="audit_type,entity,unique_identifier,tenant_id,created_by"/>
<createIndex indexName="ix_audit_log_data" tableName="audit_log" columns="data" definition="create index audit_log_values_idx on audit_log using GIN (data) " platforms="POSTGRES"/>
<createIndex indexName="ix_audit_log_changes" tableName="audit_log" columns="changes" definition="create index audit_log_changes_idx on audit_log using GIN (changes) " platforms="POSTGRES"/>
<createIndex indexName="ix_audit_log_data" tableName="audit_log" columns="data" definition="create index audit_log_values_idx on audit_log using GIN (data)" platforms="POSTGRES"/>
<createIndex indexName="ix_audit_log_changes" tableName="audit_log" columns="changes" definition="create index audit_log_changes_idx on audit_log using GIN (changes)" platforms="POSTGRES"/>
<createIndex indexName="ix_data_model_data" tableName="data_model" columns="data" definition="create index data_jsonb_idx on data_model using GIN (data) " platforms="POSTGRES"/>
</changeSet>
</migration>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<extra-ddl xmlns="http://ebean-orm.github.io/xml/ns/extraddl">
<!--<ddl-script name="1 product view">
drop view if exists product_vw cascade;
create view product_vw as
...;
</ddl-script>
<ddl-script name="2 promotion views">
&#45;&#45; 2 related/dependent views that drop and create together
drop view if exists promotion_minprice_vw cascade;
drop view if exists promotion_vw cascade;
create view promotion_vw as
...;
create view promotion_minprice_vw as
...;
</ddl-script>-->
</extra-ddl>

View File

@@ -0,0 +1,21 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- SQL and bind values -->
<logger name="io.ebean.SQL" level="TRACE"/>
<!-- Transaction Commit and Rollback events -->
<logger name="io.ebean.TXN" level="WARN"/>
<logger name="io.ebean.SUM" level="WARN"/>
<logger name="io.ebean.migration" level="TRACE"/>
<logger name="io.ebean.dbmigration" level="TRACE"/>
<logger name="io.ebean" level="TRACE"/>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>