From 6f5d4b334c7e9842a1e0aa3482f783eeb2b728eb Mon Sep 17 00:00:00 2001 From: Vincent Jousse Date: Thu, 21 Nov 2013 22:44:41 +0100 Subject: [PATCH] Import poche v2 schema --- .gitignore | 1 + README.md | 4 ++ composer.json | 3 +- console | 1 + src/Poche/Command/CreateSchemaCommand.php | 36 ++++++++++ src/Poche/Schema.php | 88 +++++++++++++++++++++++ src/Poche/Util/Token.php | 22 ++++++ src/app.php | 6 ++ 8 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/Poche/Command/CreateSchemaCommand.php create mode 100644 src/Poche/Schema.php create mode 100644 src/Poche/Util/Token.php diff --git a/.gitignore b/.gitignore index 06e0df4..4f0098c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ cache/* vendor composer.phar composer.lock +poche.db diff --git a/README.md b/README.md index 1efe5a4..ede4d6d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ If you are using PHP 5.4 you can run Poche v2 by using the embedded webserver: Poche should now be running at [http://localhost:8080](http://localhost:8080). +Then you should initialize your database by running: + + ./console db:create + # Test To run the test suite just use: diff --git a/composer.json b/composer.json index dcb639b..77644cd 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "atoum/atoum" : "dev-master", "twig/twig": ">=1.8,<2.0-dev", "symfony/twig-bridge": "~2.3", - "knplabs/console-service-provider": "dev-master" + "knplabs/console-service-provider": "dev-master", + "doctrine/dbal": "2.2.*" }, "autoload": { "psr-0": { "Poche\\": "src/" } diff --git a/console b/console index 9f3bf39..1bd5b55 100755 --- a/console +++ b/console @@ -8,5 +8,6 @@ require_once __DIR__.'/src/app.php'; $console = $app['console']; $console->add(new Poche\Command\UnitTestsCommand()); +$console->add(new Poche\Command\CreateSchemaCommand()); $console->run(); diff --git a/src/Poche/Command/CreateSchemaCommand.php b/src/Poche/Command/CreateSchemaCommand.php new file mode 100644 index 0000000..645d14a --- /dev/null +++ b/src/Poche/Command/CreateSchemaCommand.php @@ -0,0 +1,36 @@ +setName('db:create') + ->setDescription('Create default schema') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $app = $this->getSilexApplication(); + $db = $app['db']; + + Schema::executeSchema($db); + + $output->writeln("Schema created"); + } +} + diff --git a/src/Poche/Schema.php b/src/Poche/Schema.php new file mode 100644 index 0000000..30b861c --- /dev/null +++ b/src/Poche/Schema.php @@ -0,0 +1,88 @@ +query(" + CREATE TABLE config ( + name TEXT, + value TEXT + ) + "); + + $db->query(" + INSERT INTO config (name, value) + VALUES ('api_token', '". Token::generateToken()."') + "); + + + + $db->query(" + CREATE TABLE users ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, + username TEXT DEFAULT 'poche', + password TEXT, + email TEXT, + language TEXT DEFAULT 'en_US', + items_per_page INTEGER DEFAULT 100, + theme TEXT DEFAULT 'original', + items_sorting_direction TEXT DEFAULT 'desc', + api_token TEXT DEFAULT '". Token::generateToken()."', + feed_token TEXT DEFAULT '".Token::generateToken()."', + auth_google_token TEXT DEFAULT '', + auth_mozilla_token TEXT DEFAULT '' + ) + "); + + //$db->query(" + // INSERT INTO users + // (password) + // VALUES ('".\password_hash('poche', PASSWORD_BCRYPT)."') + //"); + + $db->query(' + CREATE TABLE entries ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, + url TEXT, + title TEXT, + content TEXT, + updated INTEGER, + status TEXT, + bookmark INTEGER DEFAULT 0, + fetched INTEGER DEFAULT 1, + user_id INTEGER, + FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE + ) + '); + + $db->query('CREATE INDEX idx_status ON entries(status)'); + + $db->query(' + CREATE TABLE tags ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, + value TEXT + ) + '); + + $db->query(' + CREATE TABLE tags_entries ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, + entry_id INTEGER, + tag_id INTEGER, + FOREIGN KEY(entry_id) REFERENCES entries(id) ON DELETE CASCADE, + FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE + ) + '); + + $db->query(" + CREATE TABLE plugin_options ( + name TEXT PRIMARY KEY, + value TEXT + ) + "); + } +} diff --git a/src/Poche/Util/Token.php b/src/Poche/Util/Token.php new file mode 100644 index 0000000..c6c32b0 --- /dev/null +++ b/src/Poche/Util/Token.php @@ -0,0 +1,22 @@ +register(new ConsoleServiceProvider(), [ 'console.project_directory' => __DIR__.'/..', ]); +$app->register(new Silex\Provider\DoctrineServiceProvider(), array( + 'db.options' => array( + 'driver' => 'pdo_sqlite', + 'path' => __DIR__.'/../poche.db', + ), +));