-- apply changes
create table fleet_type (
  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,
  person_incharge               varchar(255) not null,
  created_by                    varchar(255) not null,
  modified_by                   varchar(255) not null,
  constraint ck_fleet_type_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
  constraint pk_fleet_type primary key (sys_pk)
);

create table renewal (
  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,
  created_by                    varchar(255) not null,
  modified_by                   varchar(255) not null,
  constraint ck_renewal_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
  constraint pk_renewal primary key (sys_pk)
);

create table vehicle (
  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,
  created_by                    varchar(255) not null,
  modified_by                   varchar(255) not null,
  constraint ck_vehicle_approval_status check ( approval_status in ('PENDING','APPROVED','REJECTED')),
  constraint pk_vehicle primary key (sys_pk)
);

-- apply alter tables
alter table fleet add column if not exists renewals jsonb;
