Example #1
0
 public function getRelation(Database $database, array $relation)
 {
     $rname = $relation['rname'];
     $cols = $relation['cols'];
     $cons = $relation['cons'];
     return $database->create_table($rname, $cols, $cons);
 }
Example #2
0
function create_tables()
{
    // {{{
    try {
        $db = new Database();
        if ($db->count_tables() > 0) {
            print <<<EOD
\t\t\t<div id="installer">
\t\t\t\t<h1>Shimmie Installer</h1>
\t\t\t\t<h3>Warning: The Database schema is not empty!</h3>
\t\t\t\t<p>Please ensure that the database you are installing Shimmie with is empty before continuing.</p>
\t\t\t\t<p>Once you have emptied the database of any tables, please hit 'refresh' to continue.</p>
\t\t\t\t<br/><br/>
\t\t\t</div>
EOD;
            exit;
        }
        $db->create_table("aliases", "\n\t\t\toldtag VARCHAR(128) NOT NULL,\n\t\t\tnewtag VARCHAR(128) NOT NULL,\n\t\t\tPRIMARY KEY (oldtag)\n\t\t");
        $db->execute("CREATE INDEX aliases_newtag_idx ON aliases(newtag)", array());
        $db->create_table("config", "\n\t\t\tname VARCHAR(128) NOT NULL,\n\t\t\tvalue TEXT,\n\t\t\tPRIMARY KEY (name)\n\t\t");
        $db->create_table("users", "\n\t\t\tid SCORE_AIPK,\n\t\t\tname VARCHAR(32) UNIQUE NOT NULL,\n\t\t\tpass VARCHAR(250),\n\t\t\tjoindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,\n\t\t\tclass VARCHAR(32) NOT NULL DEFAULT 'user',\n\t\t\temail VARCHAR(128)\n\t\t");
        $db->execute("CREATE INDEX users_name_idx ON users(name)", array());
        $db->create_table("images", "\n\t\t\tid SCORE_AIPK,\n\t\t\towner_id INTEGER NOT NULL,\n\t\t\towner_ip SCORE_INET NOT NULL,\n\t\t\tfilename VARCHAR(64) NOT NULL,\n\t\t\tfilesize INTEGER NOT NULL,\n\t\t\thash CHAR(32) UNIQUE NOT NULL,\n\t\t\text CHAR(4) NOT NULL,\n\t\t\tsource VARCHAR(255),\n\t\t\twidth INTEGER NOT NULL,\n\t\t\theight INTEGER NOT NULL,\n\t\t\tposted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,\n\t\t\tlocked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,\n\t\t\tFOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT\n\t\t");
        $db->execute("CREATE INDEX images_owner_id_idx ON images(owner_id)", array());
        $db->execute("CREATE INDEX images_width_idx ON images(width)", array());
        $db->execute("CREATE INDEX images_height_idx ON images(height)", array());
        $db->execute("CREATE INDEX images_hash_idx ON images(hash)", array());
        $db->create_table("tags", "\n\t\t\tid SCORE_AIPK,\n\t\t\ttag VARCHAR(64) UNIQUE NOT NULL,\n\t\t\tcount INTEGER NOT NULL DEFAULT 0\n\t\t");
        $db->execute("CREATE INDEX tags_tag_idx ON tags(tag)", array());
        $db->create_table("image_tags", "\n\t\t\timage_id INTEGER NOT NULL,\n\t\t\ttag_id INTEGER NOT NULL,\n\t\t\tUNIQUE(image_id, tag_id),\n\t\t\tFOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,\n\t\t\tFOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE\n\t\t");
        $db->execute("CREATE INDEX images_tags_image_id_idx ON image_tags(image_id)", array());
        $db->execute("CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id)", array());
        $db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)");
        $db->commit();
    } catch (PDOException $e) {
        print <<<EOD
\t\t\t<div id="installer">
\t\t\t\t<h1>Shimmie Installer</h1>
\t\t\t\t<h3>Database Error:</h3>
\t\t\t\t<p>An error occured while trying to create the database tables necessary for Shimmie.</p>
\t\t\t\t<p>Please check and ensure that the database configuration options are all correct.</p>
\t\t\t\t<br/><br/>
\t\t\t</div>
EOD;
        exit($e->getMessage());
    } catch (Exception $e) {
        print <<<EOD
\t\t\t<div id="installer">
\t\t\t\t<h1>Shimmie Installer</h1>
\t\t\t\t<h3>Unknown Error:</h3>
\t\t\t\t<p>An unknown error occured while trying to create the database tables necessary for Shimmie.</p>
\t\t\t\t<p>Please check the server log files for more information.</p>
\t\t\t\t<br/><br/>
\t\t\t</div>
EOD;
        exit($e->getMessage());
    }
}
Example #3
0
function create_tables()
{
    // {{{
    try {
        $db = new Database();
        $db->create_table("aliases", "\n\t\t\toldtag VARCHAR(128) NOT NULL PRIMARY KEY,\n\t\t\tnewtag VARCHAR(128) NOT NULL,\n\t\t\tINDEX(newtag)\n\t\t");
        $db->create_table("config", "\n\t\t\tname VARCHAR(128) NOT NULL PRIMARY KEY,\n\t\t\tvalue TEXT\n\t\t");
        $db->create_table("users", "\n\t\t\tid SCORE_AIPK,\n\t\t\tname VARCHAR(32) UNIQUE NOT NULL,\n\t\t\tpass CHAR(32),\n\t\t\tjoindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,\n\t\t\tadmin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,\n\t\t\temail VARCHAR(128)\n\t\t");
        $db->create_table("images", "\n\t\t\tid SCORE_AIPK,\n\t\t\towner_id INTEGER NOT NULL,\n\t\t\towner_ip SCORE_INET NOT NULL,\n\t\t\tfilename VARCHAR(64) NOT NULL,\n\t\t\tfilesize INTEGER NOT NULL,\n\t\t\thash CHAR(32) UNIQUE NOT NULL,\n\t\t\text CHAR(4) NOT NULL,\n\t\t\tsource VARCHAR(255),\n\t\t\twidth INTEGER NOT NULL,\n\t\t\theight INTEGER NOT NULL,\n\t\t\tposted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,\n\t\t\tlocked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,\n\t\t\tINDEX(owner_id),\n\t\t\tINDEX(width),\n\t\t\tINDEX(height),\n\t\t\tFOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE\n\t\t");
        $db->create_table("tags", "\n\t\t\tid SCORE_AIPK,\n\t\t\ttag VARCHAR(64) UNIQUE NOT NULL,\n\t\t\tcount INTEGER NOT NULL DEFAULT 0\n\t\t");
        $db->create_table("image_tags", "\n\t\t\timage_id INTEGER NOT NULL,\n\t\t\ttag_id INTEGER NOT NULL,\n\t\t\tINDEX(image_id),\n\t\t\tINDEX(tag_id),\n\t\t\tUNIQUE(image_id, tag_id),\n\t\t\tFOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,\n\t\t\tFOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE\n\t\t");
        $db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)");
    } catch (PDOException $e) {
        // FIXME: Make the error message user friendly
        exit($e->getMessage());
    }
}