DROP TABLE IF EXISTS Phases;
DROP TABLE IF EXISTS GeneralInfo;
DROP TABLE IF EXISTS Comments;
DROP TABLE IF EXISTS ranges;
DROP TABLE IF EXISTS Transactions;
DROP TABLE IF EXISTS DebugMessages;
DROP TABLE IF EXISTS Power;

CREATE TABLE Phases(
        ID INTEGER PRIMARY KEY,
        PhaseName TEXT,
        PhaseBegin INTEGER,
        PhaseEnd INTEGER,
        Transact INTEGER
);

CREATE TABLE GeneralInfo(
        NumberOfTransactions INTEGER,
        TraceEnd INTEGER,
        NumberOfBanks INTEGER,
        clk INTEGER,
        UnitOfTime TEXT,
        MCconfig TEXT,
        Memspec TEXT,
        Traces TEXT,
        WindowSize INTEGER,
        FlexibleRefresh INTEGER,
        MaxRefBurst INTEGER,
        ControllerThread INTEGER
);

CREATE TABLE Power(
        time DOUBLE,
        AveragePower DOUBLE
);


CREATE TABLE Comments(
        Time INTEGER,
        Text TEXT
);

CREATE TABLE DebugMessages(
        Time INTEGER,
        Message TEXT
);

-- use SQLITE R* TREE Module to make queries on timespans effecient (see http://www.sqlite.org/rtree.html)
CREATE VIRTUAL TABLE ranges USING rtree(
   id,
   begin, end
);

CREATE TABLE Transactions(
        ID INTEGER,
        Range INTEGER,
        Address INTEGER,
        Burstlength INTEGER,
        TThread INTEGER,
        TChannel INTEGER,
        TBank INTEGER,
        TBankgroup INTEGER,
        TRow INTEGER,
        TColumn INTEGER,
        DataStrobeBegin INTEGER,
        DataStrobeEnd INTEGER,
        TimeOfGeneration INTEGER,
        Command TEXT
        );

CREATE INDEX ranges_index ON Transactions(Range);
CREATE INDEX "phasesTransactions" ON "Phases" ("Transact" ASC);
CREATE INDEX "messageTimes" ON "DebugMessages" ("Time" ASC);
