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

our $VERSION = '1';

1;

__DATA__

@@ languages

-- 1 up

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

    
CREATE TABLE IF NOT EXISTS languages_types -- 
(
    languages_types_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(),
                type  VARCHAR  UNIQUE  NOT NULL , -- Type of translation, field tooltip help etc
                CONSTRAINT languages_types_pkey PRIMARY KEY (languages_types_pkey)
);
    
CREATE TABLE IF NOT EXISTS languages_translations -- 
(
    languages_translations_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(),
            languages_lan_fkey BIGINT  NOT NULL, -- 
                    languages_translation_keys_fkey BIGINT  NOT NULL, -- 
                        translation  VARCHAR  NOT NULL , -- Translation to selected language
                        locked  BOOLEAN  NOT NULL DEFAULT false , -- Translation locked for automatic updates
                CONSTRAINT languages_translations_pkey PRIMARY KEY (languages_translations_pkey)
);
    
CREATE TABLE IF NOT EXISTS languages_lan -- 
(
    languages_lan_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(),
                language  VARCHAR  NOT NULL DEFAULT '' , -- Language full name
                        browser_code  VARCHAR  NOT NULL DEFAULT '' , -- Language code in the browser
                        iso_code  VARCHAR  UNIQUE  NOT NULL , -- Language ISO Code
                CONSTRAINT languages_lan_pkey PRIMARY KEY (languages_lan_pkey)
);
    
CREATE TABLE IF NOT EXISTS languages_translation_keys -- 
(
    languages_translation_keys_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(),
                plugin  VARCHAR  NOT NULL , -- 
                        field  VARCHAR  NOT NULL DEFAULT '' , -- Translated field
                    languages_types_fkey BIGINT  NOT NULL, -- Type of translation
                        key  VARCHAR  NOT NULL , -- Key or table the translation belongs to
                        comment  VARCHAR  NOT NULL DEFAULT '' , -- Comment to help understand context
                CONSTRAINT languages_translation_keys_pkey PRIMARY KEY (languages_translation_keys_pkey)
);
    

CREATE OR REPLACE VIEW v_languages_types AS  -- 
    SELECT languages_types_pkey, editnum, insby, insdatetime, modby, moddatetime, type
          FROM languages_types;
CREATE OR REPLACE VIEW v_languages_translations AS  -- 
    SELECT languages_translations_pkey, editnum, insby, insdatetime, modby, moddatetime,languages_lan_fkey,
     languages_translation_keys_fkey,
      translation,
      locked
          FROM languages_translations;
CREATE OR REPLACE VIEW v_languages_lan AS  -- 
    SELECT languages_lan_pkey, editnum, insby, insdatetime, modby, moddatetime, language,
      browser_code,
      iso_code
          FROM languages_lan;
CREATE OR REPLACE VIEW v_languages_translation_keys AS  -- 
    SELECT languages_translation_keys_pkey, editnum, insby, insdatetime, modby, moddatetime, plugin,
      field,
     languages_types_fkey,
      key,
      comment
          FROM languages_translation_keys;


CREATE OR REPLACE VIEW v_languages_types_list AS -- 
    SELECT languages_types_pkey, editnum, insby, insdatetime, modby, moddatetime, type     FROM languages_types;

CREATE OR REPLACE VIEW v_languages_translations_list AS -- 
    SELECT languages_translations_pkey, editnum, insby, insdatetime, modby, moddatetime,     (SELECT iso_code FROM languages_lan WHERE languages_lan_pkey = languages_lan_fkey) as languages_lan_iso_code,languages_lan_fkey,languages_translation_keys_fkey, translation, locked     FROM languages_translations;

CREATE OR REPLACE VIEW v_languages_lan_list AS -- 
    SELECT languages_lan_pkey, editnum, insby, insdatetime, modby, moddatetime, language, browser_code, iso_code     FROM languages_lan;

CREATE OR REPLACE VIEW v_languages_translation_keys_list AS -- 
    SELECT languages_translation_keys_pkey, editnum, insby, insdatetime, modby, moddatetime, plugin, field,     (SELECT type FROM languages_types WHERE languages_types_pkey = languages_types_fkey) as languages_types_type,languages_types_fkey, key, comment     FROM languages_translation_keys;



-- Load a list of translations for a specific window, from plugin and key
CREATE OR REPLACE VIEW v_languages_with_keys_list AS
    SELECT plugin, key, field,(SELECT type FROM languages_types WHERE languages_types_pkey= languages_types_fkey ) as type, translation, iso_code, languages_lan_pkey 
        FROM languages_translation_keys, languages_lan, languages_translations
    WHERE languages_translation_keys_pkey = languages_translation_keys_fkey AND languages_lan_pkey = languages_lan_fkey;


    ALTER TABLE languages_translations
    ADD CONSTRAINT languages_translations_languages_lan_fkey
        FOREIGN KEY (languages_lan_fkey)    REFERENCES languages_lan (languages_lan_pkey);

CREATE INDEX ind_languages_translations_lan_fkey
    ON languages_translations(languages_lan_fkey);

  ALTER TABLE languages_translations
    ADD CONSTRAINT languages_translations_languages_translation_keys_fkey
        FOREIGN KEY (languages_translation_keys_fkey)    REFERENCES languages_translation_keys (languages_translation_keys_pkey);

CREATE INDEX ind_languages_translations_translation_keys_fkey
    ON languages_translations(languages_translation_keys_fkey);

  
  
    
  
  
    
  
  ALTER TABLE languages_translation_keys
    ADD CONSTRAINT languages_translation_keys_languages_types_fkey
        FOREIGN KEY (languages_types_fkey)    REFERENCES languages_types (languages_types_pkey);

CREATE INDEX ind_languages_translation_keys_types_fkey
    ON languages_translation_keys(languages_types_fkey);

  
  
    

CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_languages_translation_keys_plugin_field_languages_types_fkey_key
      ON languages_translation_keys(plugin, field, languages_types_fkey, key);

CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_languages_translations_languages_lan_fkey_languages_translation_keys_fkey
      ON languages_translations(languages_lan_fkey, languages_translation_keys_fkey);



-- Default languages
INSERT INTO languages_lan (iso_code, language)
VALUES 
('SWE', 'Svenska'),
('ENG', 'English'),
('GER', 'Deutsch');

-- The different key types or translation types
INSERT INTO languages_types (type) 
VALUES 
('Label'),
('Tool tips'),
('Help'),
('Message');





-- 1 down



@@ the_end


