Data Structures

Version 5.1 by Kerem Yollu on 2025/03/21 16:06

Data Structures for KPM and database relations

Models

  • Address

  • DROP TABLE IF EXISTS public.address;

    CREATE TABLE public.address
    (
        uid SERIAL PRIMARY KEY,
        country CHAR(2) NOT NULL,              -- ISO 3166-1 alpha-2 (e.g., 'CH')
       region VARCHAR(100),                   -- State or canton
       city VARCHAR(100) NOT NULL,
        postcode VARCHAR(20) NOT NULL,
        street VARCHAR(255) NOT NULL,
       number VARCHAR(20),   
        unit VARCHAR(50),                      -- Apartment/Suite/Floor/etc.
       extra_address VARCHAR(255),            -- Additional info
       lon DOUBLE PRECISION,                  -- Longitude (optional)
       lat DOUBLE PRECISION                   -- Latitude (optional)
    )

    TABLESPACE pg_default;

    ALTER TABLE IF EXISTS public.address
       OWNER to kpm_rw;

    COMMENT ON TABLE public.address
       IS 'addresses table, instead of making use of addresses for ever company, customer and co... Prefer to make addresses table and then assign it to a company or a user etc.';
  • Company_Type

  • -- Table: public.company_type

    -- DROP TABLE IF EXISTS public.company_type;

    CREATE TABLE IF NOT EXISTS public.company_type
    (
        uid SERIAL PRIMARY KEY,
        name VARCHAR(100) COLLATE pg_catalog."default" NOT NULL,
        description VARCHAR(255) COLLATE pg_catalog."default",
        creation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )
    TABLESPACE pg_default;

    ALTER TABLE IF EXISTS public.company_type
       OWNER TO kpm_rw;

    COMMENT ON TABLE public.company_type
       IS 'Reference table for different types of companies (e.g., manufacturer, distributor, partner, etc.). Used by company table.';

    COMMENT ON COLUMN public.company_type.uid
       IS 'Unique ID for each company type';

    COMMENT ON COLUMN public.company_type.name
       IS 'Short name of the company type (e.g., Manufacturer, EMS, Partner)';

    COMMENT ON COLUMN public.company_type.description
       IS 'Optional longer description of the company type';

    COMMENT ON COLUMN public.company_type.creation_date
       IS 'Timestamp when the entry was created';

    COMMENT ON COLUMN public.company_type.updated_date
       IS 'Timestamp for when the entry was last updated (set via application logic or triggers)';