-- ============================================================================
-- Copyright (C) 2026 Alles Watt lauft
--
-- Table for customer-specific installation elements (tree structure)
-- Uses adjacency list pattern with fk_parent for hierarchy
-- ============================================================================

CREATE TABLE llx_kundenkarte_anlage
(
    rowid               integer AUTO_INCREMENT PRIMARY KEY,
    entity              integer DEFAULT 1 NOT NULL,

    ref                 varchar(64),
    label               varchar(255) NOT NULL,

    fk_soc              integer NOT NULL,
    fk_anlage_type      integer NOT NULL,
    fk_parent           integer DEFAULT 0 NOT NULL,

    fk_system           integer NOT NULL,
    fk_building_node    integer DEFAULT 0,

    manufacturer        varchar(128),
    model               varchar(128),
    serial_number       varchar(64),
    power_rating        varchar(32),

    field_values        text,

    location            varchar(255),
    installation_date   date,
    warranty_until      date,

    rang                integer DEFAULT 0,
    level               integer DEFAULT 0,

    note_private        text,
    note_public         text,

    status              tinyint DEFAULT 1 NOT NULL,

    date_creation       datetime,
    tms                 timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    fk_user_creat       integer,
    fk_user_modif       integer,
    import_key          varchar(14)
) ENGINE=innodb;
