From e4ee81d800a08a5839dcfeeb3441f2f0b4247a6f Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 17 Dec 2011 12:06:24 +0100 Subject: use migrations; automatically set up the database Signed-off-by: Florian Pritz --- INSTALL | 2 +- application/config/migration.php | 82 ++++++++++++++++---------------- application/controllers/file.php | 6 +++ application/migrations/001_add_files.php | 27 +++++++++++ db.sql | 13 ----- 5 files changed, 75 insertions(+), 55 deletions(-) create mode 100644 application/migrations/001_add_files.php delete mode 100644 db.sql diff --git a/INSTALL b/INSTALL index 17bf4d0b0..71b48ff3d 100644 --- a/INSTALL +++ b/INSTALL @@ -1,6 +1,6 @@ -* Import db.sql into your database. * Copy all files from system/application/config/example to system/application/config * Change them to fit your needs +* The necessary database tables are created automatically when accessing your pastebin * Copy htaccess.txt to .htaccess if you want shorter URLs (also change the config setting) diff --git a/application/config/migration.php b/application/config/migration.php index afa264562..9a3034565 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -1,41 +1,41 @@ -migration->latest() this is the version that schema will -| be upgraded / downgraded to. -| -*/ -$config['migration_version'] = 0; - - -/* -|-------------------------------------------------------------------------- -| Migrations Path -|-------------------------------------------------------------------------- -| -| Path to your migrations folder. -| Typically, it will be within your application path. -| Also, writing permission is required within the migrations path. -| -*/ -$config['migration_path'] = APPPATH . 'migrations/'; - - -/* End of file migration.php */ -/* Location: ./application/config/migration.php */ \ No newline at end of file +migration->latest() this is the version that schema will +| be upgraded / downgraded to. +| +*/ +$config['migration_version'] = 1; + + +/* +|-------------------------------------------------------------------------- +| Migrations Path +|-------------------------------------------------------------------------- +| +| Path to your migrations folder. +| Typically, it will be within your application path. +| Also, writing permission is required within the migrations path. +| +*/ +$config['migration_path'] = APPPATH . 'migrations/'; + + +/* End of file migration.php */ +/* Location: ./application/config/migration.php */ diff --git a/application/controllers/file.php b/application/controllers/file.php index 814464ade..470383504 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -12,6 +12,12 @@ class File extends CI_Controller { function __construct() { parent::__construct(); + + $this->load->library('migration'); + if ( ! $this->migration->current()) { + show_error($this->migration->error_string()); + } + mb_internal_encoding('UTF-8'); $this->load->helper(array('form', 'filebin')); $this->load->model('file_mod'); diff --git a/application/migrations/001_add_files.php b/application/migrations/001_add_files.php new file mode 100644 index 000000000..f1f16ea3a --- /dev/null +++ b/application/migrations/001_add_files.php @@ -0,0 +1,27 @@ +db->query(" + CREATE TABLE IF NOT EXISTS `files` ( + `hash` varchar(32) CHARACTER SET ascii NOT NULL, + `id` varchar(6) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + `filename` varchar(256) COLLATE utf8_bin NOT NULL, + `password` varchar(40) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, + `date` int(11) unsigned NOT NULL, + `mimetype` varchar(255) CHARACTER SET ascii NOT NULL, + PRIMARY KEY (`id`), + KEY `date` (`date`), + KEY `hash` (`hash`,`id`) + ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + "); + } + + public function down() + { + $this->dbforge->drop_table('files'); + } +} diff --git a/db.sql b/db.sql deleted file mode 100644 index fc2c191ea..000000000 --- a/db.sql +++ /dev/null @@ -1,13 +0,0 @@ -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; - -CREATE TABLE IF NOT EXISTS `files` ( - `hash` varchar(32) CHARACTER SET ascii NOT NULL, - `id` varchar(6) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, - `filename` varchar(256) COLLATE utf8_bin NOT NULL, - `password` varchar(40) CHARACTER SET ascii COLLATE ascii_bin DEFAULT NULL, - `date` int(11) unsigned NOT NULL, - `mimetype` varchar(255) CHARACTER SET ascii NOT NULL, - PRIMARY KEY (`id`), - KEY `date` (`date`), - KEY `hash` (`hash`,`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- cgit v1.2.3-24-g4f1b