CREATE TABLE IF NOT EXISTS CDSView (
    TechnicalName TEXT PRIMARY KEY,
    DisplayName TEXT,
    Description TEXT,
    Version TEXT,
    State TEXT,
    CreatedAt INTEGER,
    ModifiedAt INTEGER,
    PRIMARY KEY (TechnicalName)
);

CREATE INDEX IF NOT EXISTS CDSViewKey ON CDSView (TechnicalName);

CREATE TABLE IF NOT EXISTS CDSViewField (
    CDSViewTechnicalName TEXT,
    FieldName TEXT,
    Description TEXT,
    DataType TEXT,
    FieldLength TEXT,
    PRIMARY KEY (FieldName, CDSViewTechnicalName),
    FOREIGN KEY (CDSViewTechnicalName) REFERENCES CDSView (TechnicalName)
);

CREATE INDEX IF NOT EXISTS CDSViewFieldKey ON CDSViewField (CDSViewTechnicalName, FieldName);
