]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
file to update from 0.x to 1.x \o/
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Wed, 7 Aug 2013 13:46:17 +0000 (15:46 +0200)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Wed, 7 Aug 2013 13:46:17 +0000 (15:46 +0200)
inc/poche/Database.class.php
install/mysql.sql [new file with mode: 0644]
install/poche.sqlite.in [moved from db/poche.sqlite.in with 100% similarity]
install/postgres.sql [new file with mode: 0644]
install/update_sqlite_from_0_to_1.php [new file with mode: 0644]

index 034b10034bedc37b9d6b262b71cbe526eb1e5c60..8da7a994ca707080514ab7082ff9b1ab63ca60aa 100644 (file)
@@ -29,6 +29,7 @@ class Database {
         }
 
         $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+        Tools::logm('storage type ' . STORAGE);
     }
 
     private function getHandle() {
diff --git a/install/mysql.sql b/install/mysql.sql
new file mode 100644 (file)
index 0000000..cb232a8
--- /dev/null
@@ -0,0 +1,34 @@
+CREATE TABLE IF NOT EXISTS `config` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `name` varchar(255) NOT NULL,
+  `value` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1;
+
+CREATE TABLE IF NOT EXISTS `entries` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `title` varchar(255) NOT NULL,
+  `url` varchar(255) NOT NULL,
+  `is_read` tinyint(1) NOT NULL,
+  `is_fav` tinyint(1) NOT NULL,
+  `content` blob NOT NULL,
+  `user_id` int(11) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
+
+CREATE TABLE IF NOT EXISTS `users` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `username` varchar(255) NOT NULL,
+  `password` varchar(255) NOT NULL,
+  `name` int(255) NOT NULL,
+  `email` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
+
+CREATE TABLE IF NOT EXISTS `users_config` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `user_id` int(11) NOT NULL,
+  `name` varchar(255) NOT NULL,
+  `value` varchar(255) NOT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
\ No newline at end of file
similarity index 100%
rename from db/poche.sqlite.in
rename to install/poche.sqlite.in
diff --git a/install/postgres.sql b/install/postgres.sql
new file mode 100644 (file)
index 0000000..9e0e827
--- /dev/null
@@ -0,0 +1,30 @@
+CREATE TABLE config (
+    id bigserial primary key,
+    name varchar(255) NOT NULL,
+    value varchar(255) NOT NULL
+);
+
+CREATE TABLE entries (
+    id bigserial primary key,
+    title varchar(255) NOT NULL,
+    url varchar(255) NOT NULL,
+    is_read boolean DEFAULT false,
+    is_fav boolean DEFAULT false,
+    content TEXT,
+    user_id integer NOT NULL
+);
+
+CREATE TABLE users (
+    id bigserial primary key,
+    username varchar(255) NOT NULL,
+    password varchar(255) NOT NULL,
+    name varchar(255) NOT NULL,
+    email varchar(255) NOT NULL
+);
+
+CREATE TABLE users_config (
+    id bigserial primary key,
+    user_id integer NOT NULL,
+    name varchar(255) NOT NULL,
+    value varchar(255) NOT NULL
+);
\ No newline at end of file
diff --git a/install/update_sqlite_from_0_to_1.php b/install/update_sqlite_from_0_to_1.php
new file mode 100644 (file)
index 0000000..2ee6552
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+
+$db_path = 'sqlite:../db/poche.sqlite';
+$handle = new PDO($db_path);
+$handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+# Requêtes à exécuter pour mettre à jour poche.sqlite en 1.x
+
+# ajout d'un champ user_id sur la table entries
+$sql = 'ALTER TABLE entries RENAME TO tempEntries;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+$sql = 'CREATE TABLE entries (id INTEGER PRIMARY KEY, title TEXT, url TEXT, is_read NUMERIC, is_fav NUMERIC, content BLOB, user_id NUMERIC);';
+$query = $handle->prepare($sql);
+$query->execute();
+
+$sql = 'INSERT INTO entries (id, title, url, is_read, is_fav, content) SELECT id, title, url, is_read, is_fav, content FROM tempEntries;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+# Update tout pour mettre user_id = 1
+$sql = 'UPDATE entries SET user_id = 1;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+# Changement des flags pour les lus / favoris
+$sql = 'UPDATE entries SET is_read = 1 WHERE is_read = -1;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+$sql = 'UPDATE entries SET is_fav = 1 WHERE is_fav = -1;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+# Création de la table users
+$sql = 'CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT, password TEXT, name TEXT, email TEXT);';
+$query = $handle->prepare($sql);
+$query->execute();
+
+$sql = 'INSERT INTO users (username) SELECT value FROM config WHERE name = "login";';
+$query = $handle->prepare($sql);
+$query->execute();
+
+$sql = "UPDATE users SET password = (SELECT value FROM config WHERE name = 'password')";
+$query = $handle->prepare($sql);
+$query->execute();
+
+# Création de la table users_config
+$sql = 'CREATE TABLE users_config (id INTEGER PRIMARY KEY, user_id NUMERIC, name TEXT, value TEXT);';
+$query = $handle->prepare($sql);
+$query->execute();
+
+# Suppression de la table temporaire
+$sql = 'DROP TABLE tempEntries;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+# Vidage de la table de config
+$sql = 'DELETE FROM config;';
+$query = $handle->prepare($sql);
+$query->execute();
+
+echo 'welcome to poche 1.0 !';
\ No newline at end of file