/** * Constractor creates connection and checks/creates tables stucture */ public function __construct() { $dibiConfig = dibi::getConnection()->getConfig(); $dbname = isset($dibiConfig['dbname']) ? $dibiConfig['dbname'] : $dibiConfig['database']; $config = array('driver' => 'sqlite', 'profiler' => Environment::getConfig('perform')->storage_profiler, 'database' => realpath(Environment::getConfig('perform')->modelCache) . '/' . $dbname . '-storage.sdb'); parent::__construct($config, 'storage'); if (!$this->getDatabaseInfo()->hasTable('fields')) { $this->query('CREATE TABLE [fields] ([id] INTEGER NOT NULL PRIMARY KEY, [name] VARCHAR(100) NOT NULL, [table] VARCHAR(50) NOT NULL, [hash] VARCHAR(32) NOT NULL, [type] VARCHAR(50)); CREATE UNIQUE INDEX [fields_idx] on [fields] ( [name], [table]);'); } if (!$this->getDatabaseInfo()->hasTable('tables')) { $this->query('CREATE TABLE [tables] ( [id] INTEGER NOT NULL PRIMARY KEY, [name] VARCHAR(100) NOT NULL UNIQUE, [hash] VARCHAR(32) NOT NULL);'); } if (!$this->getDatabaseInfo()->hasTable('views')) { $this->query('CREATE TABLE [views] ( [id] INTEGER NOT NULL PRIMARY KEY, [name] VARCHAR(100) NOT NULL UNIQUE, [hash] VARCHAR(32) NOT NULL);'); } if (!$this->getDatabaseInfo()->hasTable('indexes')) { $this->query('CREATE TABLE [indexes] ([id] INTEGER NOT NULL PRIMARY KEY, [name] VARCHAR(100) NOT NULL, [table] VARCHAR(50) NOT NULL, [hash] VARCHAR(32) NOT NULL, [unique] BOOLEAN); CREATE UNIQUE INDEX [indexes_idx] on [indexes] ( [name], [table]);'); } }