package Daje::Database::Authorities;
use Mojo::Base -base;
use v5.42;

our $VERSION = '1';

1;

__DATA__

@@ authorities

-- 1 up

-- Autogenerated file, any changes to this file will be over written.
-- Last generated 2026-03-01 05:33:51

    
CREATE TABLE IF NOT EXISTS authorities_function_plugin_role_permission -- 
(
    authorities_function_plugin_role_permission_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
            authorities_plugin_fkey BIGINT  NOT NULL, -- Plugin
                    authorities_permissions_fkey BIGINT  NOT NULL, -- Permissions
                        description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                    authorities_function_fkey BIGINT  NOT NULL, -- Function
                    authorities_role_fkey BIGINT  NOT NULL, -- Role
                CONSTRAINT authorities_function_plugin_role_permission_pkey PRIMARY KEY (authorities_function_plugin_role_permission_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_license -- 
(
    authorities_license_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
                standard  BOOLEAN  NOT NULL DEFAULT false , -- 
                        description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                        name  VARCHAR  UNIQUE  NOT NULL , -- 
                CONSTRAINT authorities_license_pkey PRIMARY KEY (authorities_license_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_plugin -- 
(
    authorities_plugin_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
                description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                        name  VARCHAR  UNIQUE  NOT NULL , -- 
                CONSTRAINT authorities_plugin_pkey PRIMARY KEY (authorities_plugin_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_function -- 
(
    authorities_function_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
                description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                    authorities_plugin_fkey BIGINT  NOT NULL, -- 
                        name  VARCHAR  UNIQUE  NOT NULL , -- 
                CONSTRAINT authorities_function_pkey PRIMARY KEY (authorities_function_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_permissions -- 
(
    authorities_permissions_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
                permission  VARCHAR  UNIQUE  NOT NULL , -- 
                        standard  BOOLEAN  NOT NULL DEFAULT true , -- 
                        description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                CONSTRAINT authorities_permissions_pkey PRIMARY KEY (authorities_permissions_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_function_permissions -- 
(
    authorities_function_permissions_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
            authorities_function_fkey BIGINT  NOT NULL, -- 
                    authorities_permissions_fkey BIGINT  NOT NULL, -- 
                CONSTRAINT authorities_function_permissions_pkey PRIMARY KEY (authorities_function_permissions_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_license_plugin -- 
(
    authorities_license_plugin_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
            authorities_license_fkey BIGINT  NOT NULL, -- 
                    authorities_plugin_fkey BIGINT  NOT NULL, -- 
                        licensed  BOOLEAN  NOT NULL DEFAULT false , -- 
                CONSTRAINT authorities_license_plugin_pkey PRIMARY KEY (authorities_license_plugin_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_license_function -- 
(
    authorities_license_function_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
            authorities_license_fkey BIGINT  NOT NULL, -- 
                    authorities_function_fkey BIGINT  NOT NULL, -- 
                        licensed  BOOLEAN  NOT NULL DEFAULT false , -- 
                CONSTRAINT authorities_license_function_pkey PRIMARY KEY (authorities_license_function_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_role -- 
(
    authorities_role_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
                standard  BOOLEAN  NOT NULL DEFAULT false , -- Standard role, cant be changed
                        description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                    companies_companies_fkey BIGINT  , -- Select company
                    authorities_workflow_fkey BIGINT  NOT NULL, -- 
                        name  VARCHAR  NOT NULL , -- Name of role
                CONSTRAINT authorities_role_pkey PRIMARY KEY (authorities_role_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_plugin_role -- 
(
    authorities_plugin_role_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
            authorities_role_fkey BIGINT  NOT NULL, -- Reference to Role
                        description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                    authorities_plugin_fkey BIGINT  NOT NULL, -- Reference to plugin
                CONSTRAINT authorities_plugin_role_pkey PRIMARY KEY (authorities_plugin_role_pkey)
);
    
CREATE TABLE IF NOT EXISTS authorities_function_plugin_role -- 
(
    authorities_function_plugin_role_pkey  SERIAL NOT NULL,
    editnum bigint NOT NULL DEFAULT 1,
    insby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    insdatetime timestamp without time zone NOT NULL DEFAULT now(),
    modby character varying COLLATE pg_catalog."default" NOT NULL DEFAULT 'System'::character varying,
    moddatetime timestamp without time zone NOT NULL DEFAULT now(),
            authorities_role_fkey BIGINT  NOT NULL, -- Role
                    authorities_function_fkey BIGINT  NOT NULL, -- Function
                        description  VARCHAR  NOT NULL DEFAULT '' , -- Description
                    authorities_plugin_fkey BIGINT  NOT NULL, -- Plugin
                CONSTRAINT authorities_function_plugin_role_pkey PRIMARY KEY (authorities_function_plugin_role_pkey)
);
    

CREATE OR REPLACE VIEW v_authorities_function_plugin_role_permission AS  -- 
    SELECT authorities_function_plugin_role_permission_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_plugin_fkey,
     authorities_permissions_fkey,
      description,
     authorities_function_fkey,
     authorities_role_fkey
          FROM authorities_function_plugin_role_permission;
CREATE OR REPLACE VIEW v_authorities_license AS  -- 
    SELECT authorities_license_pkey, editnum, insby, insdatetime, modby, moddatetime, standard,
      description,
      name
          FROM authorities_license;
CREATE OR REPLACE VIEW v_authorities_plugin AS  -- 
    SELECT authorities_plugin_pkey, editnum, insby, insdatetime, modby, moddatetime, description,
      name
          FROM authorities_plugin;
CREATE OR REPLACE VIEW v_authorities_function AS  -- 
    SELECT authorities_function_pkey, editnum, insby, insdatetime, modby, moddatetime, description,
     authorities_plugin_fkey,
      name
          FROM authorities_function;
CREATE OR REPLACE VIEW v_authorities_permissions AS  -- 
    SELECT authorities_permissions_pkey, editnum, insby, insdatetime, modby, moddatetime, permission,
      standard,
      description
          FROM authorities_permissions;
CREATE OR REPLACE VIEW v_authorities_function_permissions AS  -- 
    SELECT authorities_function_permissions_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_function_fkey,
     authorities_permissions_fkey
          FROM authorities_function_permissions;
CREATE OR REPLACE VIEW v_authorities_license_plugin AS  -- 
    SELECT authorities_license_plugin_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_license_fkey,
     authorities_plugin_fkey,
      licensed
          FROM authorities_license_plugin;
CREATE OR REPLACE VIEW v_authorities_license_function AS  -- 
    SELECT authorities_license_function_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_license_fkey,
     authorities_function_fkey,
      licensed
          FROM authorities_license_function;
CREATE OR REPLACE VIEW v_authorities_role AS  -- 
    SELECT authorities_role_pkey, editnum, insby, insdatetime, modby, moddatetime, standard,
      description,
     companies_companies_fkey,
     authorities_workflow_fkey,
      name
          FROM authorities_role;
CREATE OR REPLACE VIEW v_authorities_plugin_role AS  -- 
    SELECT authorities_plugin_role_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_role_fkey,
      description,
     authorities_plugin_fkey
          FROM authorities_plugin_role;
CREATE OR REPLACE VIEW v_authorities_function_plugin_role AS  -- 
    SELECT authorities_function_plugin_role_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_role_fkey,
     authorities_function_fkey,
      description,
     authorities_plugin_fkey
          FROM authorities_function_plugin_role;


CREATE OR REPLACE VIEW v_authorities_function_plugin_role_permission_list AS -- 
    SELECT authorities_function_plugin_role_permission_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_plugin_fkey,authorities_permissions_fkey, description,authorities_function_fkey,authorities_role_fkey     FROM authorities_function_plugin_role_permission;

CREATE OR REPLACE VIEW v_authorities_license_list AS -- 
    SELECT authorities_license_pkey, editnum, insby, insdatetime, modby, moddatetime, standard, description, name     FROM authorities_license;

CREATE OR REPLACE VIEW v_authorities_plugin_list AS -- 
    SELECT authorities_plugin_pkey, editnum, insby, insdatetime, modby, moddatetime, description, name     FROM authorities_plugin;

CREATE OR REPLACE VIEW v_authorities_function_list AS -- 
    SELECT authorities_function_pkey, editnum, insby, insdatetime, modby, moddatetime, description,authorities_plugin_fkey, name     FROM authorities_function;

CREATE OR REPLACE VIEW v_authorities_permissions_list AS -- 
    SELECT authorities_permissions_pkey, editnum, insby, insdatetime, modby, moddatetime, permission, standard, description     FROM authorities_permissions;

CREATE OR REPLACE VIEW v_authorities_function_permissions_list AS -- 
    SELECT authorities_function_permissions_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_function_fkey,authorities_permissions_fkey     FROM authorities_function_permissions;

CREATE OR REPLACE VIEW v_authorities_license_plugin_list AS -- 
    SELECT authorities_license_plugin_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_license_fkey,authorities_plugin_fkey, licensed     FROM authorities_license_plugin;

CREATE OR REPLACE VIEW v_authorities_license_function_list AS -- 
    SELECT authorities_license_function_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_license_fkey,authorities_function_fkey, licensed     FROM authorities_license_function;

CREATE OR REPLACE VIEW v_authorities_role_list AS -- 
    SELECT authorities_role_pkey, editnum, insby, insdatetime, modby, moddatetime, standard, description,companies_companies_fkey,authorities_workflow_fkey, name     FROM authorities_role;

CREATE OR REPLACE VIEW v_authorities_plugin_role_list AS -- 
    SELECT authorities_plugin_role_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_role_fkey, description,authorities_plugin_fkey     FROM authorities_plugin_role;

CREATE OR REPLACE VIEW v_authorities_function_plugin_role_list AS -- 
    SELECT authorities_function_plugin_role_pkey, editnum, insby, insdatetime, modby, moddatetime,authorities_role_fkey,authorities_function_fkey, description,authorities_plugin_fkey     FROM authorities_function_plugin_role;




ALTER TABLE authorities_function_plugin_role_permission
    ADD CONSTRAINT authorities_function_plugin_role_permission_authorities_plugin_fkey
        FOREIGN KEY (authorities_plugin_fkey)    REFERENCES authorities_plugin (authorities_plugin_pkey);

CREATE INDEX ind_authorities_function_plugin_role_permission_plugin_fkey
    ON authorities_function_plugin_role_permission(authorities_plugin_fkey);

  ALTER TABLE authorities_function_plugin_role_permission
    ADD CONSTRAINT authorities_function_plugin_role_permission_authorities_permissions_fkey
        FOREIGN KEY (authorities_permissions_fkey)    REFERENCES authorities_permissions (authorities_permissions_pkey);

CREATE INDEX ind_authorities_function_plugin_role_permission_permissions_fkey
    ON authorities_function_plugin_role_permission(authorities_permissions_fkey);

  
  ALTER TABLE authorities_function_plugin_role_permission
    ADD CONSTRAINT authorities_function_plugin_role_permission_authorities_function_fkey
        FOREIGN KEY (authorities_function_fkey)    REFERENCES authorities_function (authorities_function_pkey);

CREATE INDEX ind_authorities_function_plugin_role_permission_function_fkey
    ON authorities_function_plugin_role_permission(authorities_function_fkey);

  ALTER TABLE authorities_function_plugin_role_permission
    ADD CONSTRAINT authorities_function_plugin_role_permission_authorities_role_fkey
        FOREIGN KEY (authorities_role_fkey)    REFERENCES authorities_role (authorities_role_pkey);

CREATE INDEX ind_authorities_function_plugin_role_permission_role_fkey
    ON authorities_function_plugin_role_permission(authorities_role_fkey);

    
  
  
    
  
    
  ALTER TABLE authorities_function
    ADD CONSTRAINT authorities_function_authorities_plugin_fkey
        FOREIGN KEY (authorities_plugin_fkey)    REFERENCES authorities_plugin (authorities_plugin_pkey);

CREATE INDEX ind_authorities_function_plugin_fkey
    ON authorities_function(authorities_plugin_fkey);

  
    
  
  
    ALTER TABLE authorities_function_permissions
    ADD CONSTRAINT authorities_function_permissions_authorities_function_fkey
        FOREIGN KEY (authorities_function_fkey)    REFERENCES authorities_function (authorities_function_pkey);

CREATE INDEX ind_authorities_function_permissions_function_fkey
    ON authorities_function_permissions(authorities_function_fkey);

  ALTER TABLE authorities_function_permissions
    ADD CONSTRAINT authorities_function_permissions_authorities_permissions_fkey
        FOREIGN KEY (authorities_permissions_fkey)    REFERENCES authorities_permissions (authorities_permissions_pkey);

CREATE INDEX ind_authorities_function_permissions_permissions_fkey
    ON authorities_function_permissions(authorities_permissions_fkey);

    ALTER TABLE authorities_license_plugin
    ADD CONSTRAINT authorities_license_plugin_authorities_license_fkey
        FOREIGN KEY (authorities_license_fkey)    REFERENCES authorities_license (authorities_license_pkey);

CREATE INDEX ind_authorities_license_plugin_license_fkey
    ON authorities_license_plugin(authorities_license_fkey);

  ALTER TABLE authorities_license_plugin
    ADD CONSTRAINT authorities_license_plugin_authorities_plugin_fkey
        FOREIGN KEY (authorities_plugin_fkey)    REFERENCES authorities_plugin (authorities_plugin_pkey);

CREATE INDEX ind_authorities_license_plugin_plugin_fkey
    ON authorities_license_plugin(authorities_plugin_fkey);

  
    ALTER TABLE authorities_license_function
    ADD CONSTRAINT authorities_license_function_authorities_license_fkey
        FOREIGN KEY (authorities_license_fkey)    REFERENCES authorities_license (authorities_license_pkey);

CREATE INDEX ind_authorities_license_function_license_fkey
    ON authorities_license_function(authorities_license_fkey);

  ALTER TABLE authorities_license_function
    ADD CONSTRAINT authorities_license_function_authorities_function_fkey
        FOREIGN KEY (authorities_function_fkey)    REFERENCES authorities_function (authorities_function_pkey);

CREATE INDEX ind_authorities_license_function_function_fkey
    ON authorities_license_function(authorities_function_fkey);

  
    
  
  ALTER TABLE authorities_role
    ADD CONSTRAINT companies_role_companies_companies_fkey
        FOREIGN KEY (companies_companies_fkey)    REFERENCES companies_companies (companies_companies_pkey);


CREATE INDEX ind_companies_role_companies_fkey
    ON authorities_role(companies_companies_fkey);

  
  ALTER TABLE authorities_role
    ADD CONSTRAINT authorities_role_authorities_workflow_fkey
        FOREIGN KEY (authorities_workflow_fkey)
    REFERENCES workflow (workflow_pkey);
CREATE INDEX ind_authorities_role_workflow_fkey
    ON authorities_role(authorities_workflow_fkey);

  
    ALTER TABLE authorities_plugin_role
    ADD CONSTRAINT authorities_plugin_role_authorities_role_fkey
        FOREIGN KEY (authorities_role_fkey)    REFERENCES authorities_role (authorities_role_pkey);

CREATE INDEX ind_authorities_plugin_role_role_fkey
    ON authorities_plugin_role(authorities_role_fkey);

  
  ALTER TABLE authorities_plugin_role
    ADD CONSTRAINT authorities_plugin_role_authorities_plugin_fkey
        FOREIGN KEY (authorities_plugin_fkey)    REFERENCES authorities_plugin (authorities_plugin_pkey);

CREATE INDEX ind_authorities_plugin_role_plugin_fkey
    ON authorities_plugin_role(authorities_plugin_fkey);

    ALTER TABLE authorities_function_plugin_role
    ADD CONSTRAINT authorities_function_plugin_role_authorities_role_fkey
        FOREIGN KEY (authorities_role_fkey)    REFERENCES authorities_role (authorities_role_pkey);

CREATE INDEX ind_authorities_function_plugin_role_role_fkey
    ON authorities_function_plugin_role(authorities_role_fkey);

  ALTER TABLE authorities_function_plugin_role
    ADD CONSTRAINT authorities_function_plugin_role_authorities_function_fkey
        FOREIGN KEY (authorities_function_fkey)    REFERENCES authorities_function (authorities_function_pkey);

CREATE INDEX ind_authorities_function_plugin_role_function_fkey
    ON authorities_function_plugin_role(authorities_function_fkey);

  
  ALTER TABLE authorities_function_plugin_role
    ADD CONSTRAINT authorities_function_plugin_role_authorities_plugin_fkey
        FOREIGN KEY (authorities_plugin_fkey)    REFERENCES authorities_plugin (authorities_plugin_pkey);

CREATE INDEX ind_authorities_function_plugin_role_plugin_fkey
    ON authorities_function_plugin_role(authorities_plugin_fkey);

    



-- Permissions
INSERT INTO authorities_permissions (permission, standard, description) VALUES 
('read', true,'Read permission'),
('update', true, 'Update permission'),
('create', true, 'Create permission'),
('delete', true, 'Delete permission'),
('import', true,'Import permission'),
('export', true,'Export permission');

-- license
INSERT INTO authorities_license 
(name, standard)  
VALUES ('full', true);





-- 1 down



@@ the_end


