create table meta
(
    version_num INTEGER
                NOT NULL
);

create table controllers
(
    id          VARCHAR(64)
                NOT NULL
                PRIMARY KEY
                UNIQUE,
    name        VARCHAR(128),
    ip          VARCHAR(16),
    port        INTEGER,
    relay_count INTEGER,
    tag         varchar(64),
    active      BOOLEAN
                NOT NULL
);

create table relays
(
    id              INTEGER
                    PRIMARY KEY
                    AUTOINCREMENT,
    name            VARCHAR(128),
    number          INTEGER
                    NOT NULL,
    controller_id   VARCHAR(33)
                    NOT NULL
                    REFERENCES CONTROLLERS (ID),
    schedules_ids   INTEGER
                    REFERENCES SCHEDULES (ID),
    tag             vARCHAR(64)
);

create table schedules
(
    id      INTEGER
            PRIMARY KEY
            AUTOINCREMENT,
    uid     VARCHAR(33)
            NOT NULL
            UNIQUE,
    name    VARCHAR(128),
    periods BLOB,
    tag     vARCHAR(64)
);

INSERT INTO schedules (uid, name, periods) VALUES (x'6f666600000000000000000000000000', 'off', x'00');
INSERT INTO schedules (uid, name, periods) VALUES (x'6f6e0000000000000000000000000000',  'on', x'010000009F05');
