Closed #44
This commit is contained in:
parent
b4186a218c
commit
230f555da9
4 changed files with 120 additions and 0 deletions
4
init.php
4
init.php
|
@ -52,3 +52,7 @@ download('http://raw.github.com/aehlke/tag-it/master/js/tag-it.min.js', $libPath
|
|||
//fonts
|
||||
download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans.ttf', $fontsPath . 'DroidSans.ttf');
|
||||
download('http://googlefontdirectory.googlecode.com/hg/apache/droidsans/DroidSans-Bold.ttf', $fontsPath . 'DroidSans-Bold.ttf');
|
||||
|
||||
|
||||
|
||||
require_once 'upgrade.php';
|
||||
|
|
84
src/Upgrades/Upgrade1.sql
Normal file
84
src/Upgrades/Upgrade1.sql
Normal file
|
@ -0,0 +1,84 @@
|
|||
CREATE TABLE user
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT,
|
||||
pass_salt TEXT,
|
||||
pass_hash TEXT,
|
||||
staff_confirmed INTEGER,
|
||||
email_unconfirmed TEXT,
|
||||
email_confirmed TEXT,
|
||||
email_token TEXT,
|
||||
join_date INTEGER,
|
||||
access_rank INTEGER,
|
||||
settings TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE tag
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE post_tag
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tag_id INTEGER,
|
||||
post_id INTEGER,
|
||||
FOREIGN KEY(tag_id) REFERENCES tag(id) ON DELETE CASCADE ON UPDATE SET NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES post(id) ON DELETE CASCADE ON UPDATE SET NULL
|
||||
);
|
||||
CREATE INDEX idx_fk_post_tag_post_id ON post_tag(post_id);
|
||||
CREATE INDEX idx_fk_post_tag_tag_id ON post_tag(tag_id);
|
||||
CREATE UNIQUE INDEX idx_uq_post_tag_tag_id_post_id ON post_tag(tag_id, post_id);
|
||||
|
||||
CREATE TABLE favoritee
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER,
|
||||
user_id INTEGER,
|
||||
FOREIGN KEY(user_id) REFERENCES user(id) ON DELETE CASCADE ON UPDATE SET NULL,
|
||||
FOREIGN KEY(post_id) REFERENCES post(id) ON DELETE CASCADE ON UPDATE SET NULL
|
||||
);
|
||||
CREATE INDEX idx_fk_favoritee_post_id ON favoritee(post_id);
|
||||
CREATE INDEX idx_fk_favoritee_user_id ON favoritee(user_id);
|
||||
CREATE UNIQUE INDEX idx_uq_favoritee_post_id_user_id ON favoritee(post_id, user_id);
|
||||
|
||||
CREATE TABLE comment
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
post_id INTEGER,
|
||||
commenter_id INTEGER,
|
||||
comment_date INTEGER,
|
||||
text TEXT,
|
||||
FOREIGN KEY(post_id) REFERENCES post(id) ON DELETE CASCADE ON UPDATE SET NULL,
|
||||
FOREIGN KEY(commenter_id) REFERENCES user(id) ON DELETE SET NULL ON UPDATE SET NULL
|
||||
);
|
||||
CREATE INDEX idx_fk_comment_commenter_id ON comment(commenter_id);
|
||||
CREATE INDEX idx_fk_comment_post_id ON comment(post_id);
|
||||
|
||||
CREATE TABLE post
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
type INTEGER,
|
||||
name TEXT,
|
||||
orig_name TEXT,
|
||||
file_hash TEXT,
|
||||
file_size INTEGER,
|
||||
mime_type TEXT,
|
||||
safety INTEGER,
|
||||
hidden INTEGER,
|
||||
upload_date INTEGER,
|
||||
image_width INTEGER,
|
||||
image_height INTEGER,
|
||||
uploader_id INTEGER,
|
||||
source TEXT,
|
||||
FOREIGN KEY(uploader_id) REFERENCES user(id) ON DELETE SET NULL ON UPDATE SET NULL
|
||||
);
|
||||
CREATE INDEX idx_fk_post_uploader_id ON post(uploader_id);
|
||||
|
||||
CREATE TABLE property
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
prop_id INTEGER,
|
||||
value TEXT
|
||||
);
|
|
@ -43,6 +43,7 @@ function configFactory()
|
|||
|
||||
$config = configFactory();
|
||||
R::setup('sqlite:' . $config->main->dbPath);
|
||||
R::freeze(true);
|
||||
R::dependencies(['tag' => ['post'], 'favoritee' => ['post', 'user'], 'comment' => ['post', 'user']]);
|
||||
|
||||
//wire models
|
||||
|
|
31
upgrade.php
Normal file
31
upgrade.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
require_once 'src/core.php';
|
||||
$config = configFactory();
|
||||
|
||||
$dbVersion = Model_Property::get('db-version');
|
||||
printf('DB version = %d' . PHP_EOL, $dbVersion);
|
||||
|
||||
$upgrades = glob('src/Upgrades/*.sql');
|
||||
natcasesort($upgrades);
|
||||
|
||||
foreach ($upgrades as $upgradePath)
|
||||
{
|
||||
preg_match('/(\d+)\.sql/', $upgradePath, $matches);
|
||||
$upgradeVersion = intval($matches[1]);
|
||||
|
||||
if ($upgradeVersion > $dbVersion)
|
||||
{
|
||||
printf('Executing %s...' . PHP_EOL, $upgradePath);
|
||||
$upgradeSql = file_get_contents($upgradePath);
|
||||
$queries = preg_split('/;\s*[\r\n]+/s', $upgradeSql);
|
||||
$queries = array_map('trim', $queries);
|
||||
foreach ($queries as $query)
|
||||
{
|
||||
echo $query . PHP_EOL;
|
||||
R::exec($query);
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
Model_Property::set('db-version', $upgradeVersion);
|
||||
}
|
Loading…
Reference in a new issue