add entities and db migrations

This commit is contained in:
2024-01-17 18:36:44 +05:30
parent 1abf482a7a
commit f440ca89f3
11 changed files with 403 additions and 4 deletions

View File

@@ -0,0 +1,140 @@
-- apply changes
create table document (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
deleted boolean default false 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) default 'APPROVED' not null,
tags varchar[] default '{}' not null,
comments jsonb default '[]' not null,
tenant_id varchar(255) not null,
name varchar(255) not null,
type_of_doc varchar(255) not null,
description varchar(255) not null,
url varchar(255) not null,
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_document_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
constraint pk_document primary key (sys_pk)
);
create table product (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
deleted boolean default false 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) default 'APPROVED' not null,
tags varchar[] default '{}' not null,
comments jsonb default '[]' not null,
tenant_id varchar(255) not null,
name varchar(255) not null,
description varchar(255) not null,
hsn_code varchar(255) not null,
uom varchar(3),
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_product_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
constraint ck_product_uom check ( uom in ('NOS','LTR','MTR')),
constraint pk_product primary key (sys_pk)
);
create table purchase_order (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
vendor_sys_pk bigint,
total_amount integer not null,
po_date date,
valid_till date,
documents bigint[] not null,
deleted boolean default false 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) default 'APPROVED' not null,
tags varchar[] default '{}' not null,
comments jsonb default '[]' not null,
tenant_id varchar(255) not null,
products jsonb not null,
reference_quotation varchar(255) not null,
po_num varchar(255) not null,
tnc varchar[] not null,
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_purchase_order_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
constraint pk_purchase_order primary key (sys_pk)
);
create table quotation (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
vendor_sys_pk bigint,
total_amount integer not null,
quote_date date,
valid_till date,
documents bigint[] not null,
deleted boolean default false 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) default 'APPROVED' not null,
tags varchar[] default '{}' not null,
comments jsonb default '[]' not null,
tenant_id varchar(255) not null,
products jsonb not null,
quote_num varchar(255) not null,
tnc varchar[] not null,
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_quotation_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
constraint pk_quotation primary key (sys_pk)
);
create table vendor (
sys_pk bigint generated by default as identity not null,
deleted_on timestamp,
current_approval_level integer default 0 not null,
required_approval_levels integer default 0 not null,
rating float not null,
deleted boolean default false 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) default 'APPROVED' not null,
tags varchar[] default '{}' not null,
comments jsonb default '[]' not null,
tenant_id varchar(255) not null,
name varchar(255) not null,
msme varchar(255) not null,
gst_number varchar(255) not null,
address varchar(255) not null,
contacts jsonb not null,
created_by varchar(255) not null,
modified_by varchar(255) not null,
constraint ck_vendor_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
constraint pk_vendor primary key (sys_pk)
);
-- foreign keys and indices
create index ix_purchase_order_vendor_sys_pk on purchase_order (vendor_sys_pk);
alter table purchase_order add constraint fk_purchase_order_vendor_sys_pk foreign key (vendor_sys_pk) references vendor (sys_pk) on delete restrict on update restrict;
create index ix_quotation_vendor_sys_pk on quotation (vendor_sys_pk);
alter table quotation add constraint fk_quotation_vendor_sys_pk foreign key (vendor_sys_pk) references vendor (sys_pk) on delete restrict on update restrict;

View File

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<migration xmlns="http://ebean-orm.github.io/xml/ns/dbmigration">
<changeSet type="apply">
<createTable name="document" pkName="pk_document">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<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_document_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="type_of_doc" type="varchar" notnull="true"/>
<column name="description" type="varchar" notnull="true"/>
<column name="url" type="varchar" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" 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="product" pkName="pk_product">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<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_product_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="description" type="varchar" notnull="true"/>
<column name="hsn_code" type="varchar" notnull="true"/>
<column name="uom" type="varchar(3)" checkConstraint="check ( uom in ('NOS','LTR','MTR'))" checkConstraintName="ck_product_uom"/>
<column name="deleted" type="boolean" defaultValue="false" 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="purchase_order" pkName="pk_purchase_order">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<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_purchase_order_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="products" type="jsonb" notnull="true"/>
<column name="vendor_sys_pk" type="bigint" references="vendor.sys_pk" foreignKeyName="fk_purchase_order_vendor_sys_pk" foreignKeyIndex="ix_purchase_order_vendor_sys_pk"/>
<column name="reference_quotation" type="varchar" notnull="true"/>
<column name="total_amount" type="integer" notnull="true"/>
<column name="po_num" type="varchar" notnull="true"/>
<column name="po_date" type="date"/>
<column name="valid_till" type="date"/>
<column name="tnc" type="varchar[]" notnull="true"/>
<column name="documents" type="bigint[]" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" 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="quotation" pkName="pk_quotation">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<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_quotation_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="products" type="jsonb" notnull="true"/>
<column name="vendor_sys_pk" type="bigint" references="vendor.sys_pk" foreignKeyName="fk_quotation_vendor_sys_pk" foreignKeyIndex="ix_quotation_vendor_sys_pk"/>
<column name="total_amount" type="integer" notnull="true"/>
<column name="quote_num" type="varchar" notnull="true"/>
<column name="quote_date" type="date"/>
<column name="valid_till" type="date"/>
<column name="tnc" type="varchar[]" notnull="true"/>
<column name="documents" type="bigint[]" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" 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="vendor" pkName="pk_vendor">
<column name="sys_pk" type="bigint" primaryKey="true"/>
<column name="deleted_on" type="localdatetime"/>
<column name="deleted_by" type="varchar"/>
<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_vendor_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="msme" type="varchar" notnull="true"/>
<column name="gst_number" type="varchar" notnull="true"/>
<column name="address" type="varchar" notnull="true"/>
<column name="rating" type="double" notnull="true"/>
<column name="contacts" type="jsonb" notnull="true"/>
<column name="deleted" type="boolean" defaultValue="false" 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>
</changeSet>
</migration>