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

our $VERSION = '1';

1;

__DATA__

@@ users

-- 1 up

-- Autogenerated file, any changes to this file will be over written.
-- Last generated 2026-02-27 18:02:25

    
CREATE TABLE IF NOT EXISTS users_users -- 
(
    users_users_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(),
            users_workflow_fkey BIGINT  NOT NULL, -- This users workflow
                        avatar  VARCHAR  NOT NULL DEFAULT '' , -- Users avatar
                        password  VARCHAR  NOT NULL , -- Must be minimum 8 characters long and a mix of upper and lowercase and numbers
                        active  BOOLEAN  NOT NULL DEFAULT true , -- Is user active ?
                        mail  VARCHAR  UNIQUE  NOT NULL , -- eMail address of the user, must be a valid eMail address
                        name  VARCHAR  NOT NULL DEFAULT '' , -- Full name of user
                        comment  VARCHAR  NOT NULL DEFAULT '' , -- Comment regarding user
                        position  VARCHAR  NOT NULL DEFAULT '' , -- Position in the organisation
                        biography  VARCHAR  NOT NULL DEFAULT '' , -- Users biography
                    authorities_role_fkey BIGINT  , -- Users role, decides authorities 
                        phone  VARCHAR  NOT NULL DEFAULT '' , -- Users phone number
                        department  VARCHAR  NOT NULL DEFAULT '' , -- Department where user works
                        employed  BOOLEAN  NOT NULL DEFAULT true , -- Is user employed or external
                    languages_lan_fkey BIGINT  NOT NULL, -- Users preferred language
                        verified  BOOLEAN  NOT NULL DEFAULT false , -- Is the users eMail verified ?
                CONSTRAINT users_users_pkey PRIMARY KEY (users_users_pkey)
);
    
CREATE TABLE IF NOT EXISTS users_verification_codes -- 
(
    users_verification_codes_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(),
                verification_code  VARCHAR  NOT NULL , -- Verification code
                    users_users_fkey BIGINT UNIQUE NOT NULL, -- User thats connected to verification code
                CONSTRAINT users_verification_codes_pkey PRIMARY KEY (users_verification_codes_pkey)
);
    
CREATE TABLE IF NOT EXISTS users_documentation -- 
(
    users_documentation_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(),
                document_name  VARCHAR  NOT NULL , -- Name of the document
                    users_users_fkey BIGINT  NOT NULL, -- User document belongs to
                        document_type  VARCHAR  NOT NULL , -- Document type
                CONSTRAINT users_documentation_pkey PRIMARY KEY (users_documentation_pkey)
);
    

CREATE OR REPLACE VIEW v_users_users AS  -- 
    SELECT users_users_pkey, editnum, insby, insdatetime, modby, moddatetime,users_workflow_fkey,
      avatar,
      password,
      active,
      mail,
      name,
      comment,
      position,
      biography,
     authorities_role_fkey,
      phone,
      department,
      employed,
     languages_lan_fkey,
      verified
          FROM users_users;
CREATE OR REPLACE VIEW v_users_verification_codes AS  -- 
    SELECT users_verification_codes_pkey, editnum, insby, insdatetime, modby, moddatetime, verification_code,
     users_users_fkey
          FROM users_verification_codes;
CREATE OR REPLACE VIEW v_users_documentation AS  -- 
    SELECT users_documentation_pkey, editnum, insby, insdatetime, modby, moddatetime, document_name,
     users_users_fkey,
      document_type
          FROM users_documentation;


CREATE OR REPLACE VIEW v_users_users_list AS -- 
    SELECT users_users_pkey, editnum, insby, insdatetime, modby, moddatetime,users_workflow_fkey, avatar, password, active, mail, name, comment, position, biography,      (SELECT name FROM authorities_role WHERE authorities_role_pkey = authorities_role_fkey) as authorities_role_name,authorities_role_fkey, phone, department, employed,      (SELECT iso_code FROM languages_lan WHERE languages_lan_pkey = languages_lan_fkey) as languages_lan_iso_code,languages_lan_fkey, verified     FROM users_users;

CREATE OR REPLACE VIEW v_users_verification_codes_list AS -- 
    SELECT users_verification_codes_pkey, editnum, insby, insdatetime, modby, moddatetime, verification_code,users_users_fkey     FROM users_verification_codes;

CREATE OR REPLACE VIEW v_users_documentation_list AS -- 
    SELECT users_documentation_pkey, editnum, insby, insdatetime, modby, moddatetime, document_name,users_users_fkey, document_type     FROM users_documentation;




ALTER TABLE users_users
    ADD CONSTRAINT users_users_users_workflow_fkey
        FOREIGN KEY (users_workflow_fkey)
    REFERENCES workflow (workflow_pkey);
CREATE INDEX ind_users_users_workflow_fkey
    ON users_users(users_workflow_fkey);

  
  
  
  
  
  
  
  
  ALTER TABLE users_users
    ADD CONSTRAINT authorities_users_authorities_role_fkey
        FOREIGN KEY (authorities_role_fkey)    REFERENCES authorities_role (authorities_role_pkey);


CREATE INDEX ind_authorities_users_role_fkey
    ON users_users(authorities_role_fkey);

  
  
  
  
  ALTER TABLE users_users
    ADD CONSTRAINT languages_users_languages_lan_fkey
        FOREIGN KEY (languages_lan_fkey)    REFERENCES languages_lan (languages_lan_pkey);


CREATE INDEX ind_languages_users_lan_fkey
    ON users_users(languages_lan_fkey);

  
  
    
  ALTER TABLE users_verification_codes
    ADD CONSTRAINT users_verification_codes_users_users_fkey
        FOREIGN KEY (users_users_fkey)    REFERENCES users_users (users_users_pkey);

CREATE INDEX ind_users_verification_codes_users_fkey
    ON users_verification_codes(users_users_fkey);

    
  ALTER TABLE users_documentation
    ADD CONSTRAINT users_documentation_users_users_fkey
        FOREIGN KEY (users_users_fkey)    REFERENCES users_users (users_users_pkey);

CREATE INDEX ind_users_documentation_users_fkey
    ON users_documentation(users_users_fkey);

  
    







-- 1 down



@@ the_end


