From b75c5a0bcfa98d1fbb99ababd3ad9d40099e81f5 Mon Sep 17 00:00:00 2001 From: Karl Hughes Date: Sat, 8 Apr 2017 17:03:59 -0500 Subject: [PATCH] Making mysql and postgres test suites adaptable --- tests/MysqlTest.php | 132 +++++- tests/PostgresqlTest.php | 116 ++++- tests/data/blog_mysql_55.sql | 148 +++++++ tests/data/blog_mysql_56.sql | 149 +++++++ .../{blog_mysql.sql => blog_mysql_57.sql} | 0 tests/data/blog_postgresql_91.sql | 383 ++++++++++++++++ tests/data/blog_postgresql_91_gis.sql | 416 ++++++++++++++++++ tests/data/blog_postgresql_92.sql | 383 ++++++++++++++++ tests/data/blog_postgresql_92_gis.sql | 416 ++++++++++++++++++ tests/data/blog_postgresql_94.sql | 383 ++++++++++++++++ ...tgresql.sql => blog_postgresql_94_gis.sql} | 0 11 files changed, 2518 insertions(+), 8 deletions(-) create mode 100644 tests/data/blog_mysql_55.sql create mode 100644 tests/data/blog_mysql_56.sql rename tests/data/{blog_mysql.sql => blog_mysql_57.sql} (100%) create mode 100644 tests/data/blog_postgresql_91.sql create mode 100644 tests/data/blog_postgresql_91_gis.sql create mode 100644 tests/data/blog_postgresql_92.sql create mode 100644 tests/data/blog_postgresql_92_gis.sql create mode 100644 tests/data/blog_postgresql_94.sql rename tests/data/{blog_postgresql.sql => blog_postgresql_94_gis.sql} (100%) diff --git a/tests/MysqlTest.php b/tests/MysqlTest.php index d90d1285..3a7665c9 100644 --- a/tests/MysqlTest.php +++ b/tests/MysqlTest.php @@ -4,6 +4,10 @@ class MysqlTest extends PHP_CRUD_API_Test { + const MYSQL_56 = 50600; + const MYSQL_57 = 50700; + public static $mysql_version; + public static function setUpBeforeClass() { self::setConfig('MySQL'); @@ -21,8 +25,6 @@ public function seedDatabase() die("Configure database in 'config.php' before running tests.\n"); } - $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql'; - $link = mysqli_connect( static::$config['hostname'], static::$config['username'], @@ -34,16 +36,138 @@ public function seedDatabase() die("Connect failed: ".mysqli_connect_error()."\n"); } + // Note: For some reason this version is formatted: + // $mysql_version = main_version * 10000 + minor_version * 100 + sub_version + static::$mysql_version = mysqli_get_server_version($link); + $seed_file = self::getSeedFile(); + mysqli_set_charset($link,'utf8'); $i=0; - if (mysqli_multi_query($link, file_get_contents($fixture))) { + if (mysqli_multi_query($link, file_get_contents($seed_file))) { do { $i++; mysqli_next_result($link); } while (mysqli_more_results($link)); } if (mysqli_errno($link)) { - die("Loading '$fixture' failed on statemement #$i with error:\n".mysqli_error($link)."\n"); + die("Loading '$seed_file' failed on statemement #$i with error:\n".mysqli_error($link)."\n"); } mysqli_close($link); } + + /** + * Gets the path to the seed file based on the version of MySQL + * + * @return string + */ + protected static function getSeedFile() + { + if (static::$mysql_version >= self::MYSQL_57) { + return __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'_57.sql'; + } elseif (static::$mysql_version >= self::MYSQL_56) { + return __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'_56.sql'; + } + return __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'_55.sql'; + } + + public function testHidingPasswordColumn() + { + parent::testHidingPasswordColumn(); + } + + public function testMissingIntermediateTable() + { + $test = new API($this, static::$config); + $test->get('/users?include=posts,tags'); + $test->expect('{"users":{"columns":["id","username","location"],"records":[[1,"user1",null]]},"posts":{"relations":{"user_id":"users.id"},"columns":["id","user_id","category_id","content"],"records":[[1,1,1,"blog started"],[2,1,2,"It works!"]]},"post_tags":{"relations":{"post_id":"posts.id"},"columns":["id","post_id","tag_id"],"records":[[1,1,1],[2,1,2],[3,2,1],[4,2,2]]},"tags":{"relations":{"id":"post_tags.tag_id"},"columns":["id","name"],"records":[[1,"funny"],[2,"important"]]}}'); + } + + public function testEditUserPassword() + { + parent::testEditUserPassword(); + } + + public function testEditUserLocation() + { + parent::testEditUserLocation(); + } + + public function testListUserLocations() + { + parent::testListUserLocations(); + } + + public function testEditUserWithId() + { + parent::testEditUserWithId(); + } + + public function testReadOtherUser() + { + parent::testReadOtherUser(); + } + + public function testEditOtherUser() + { + parent::testEditOtherUser(); + } + + public function testSpatialFilterWithin() + { + if (static::$mysql_version < self::MYSQL_56) { + $this->markTestSkipped("MySQL < 5.6 does not support JSON fields."); + } + parent::testSpatialFilterWithin(); + } + + + public function testListProductsProperties() + { + if (static::$mysql_version < self::MYSQL_57) { + $this->markTestSkipped("MySQL < 5.7 does not support JSON fields."); + } + parent::testListProductsProperties(); + } + + public function testReadProductProperties() + { + if (static::$mysql_version < self::MYSQL_57) { + $this->markTestSkipped("MySQL < 5.7 does not support JSON fields."); + } + parent::testReadProductProperties(); + } + + public function testWriteProductProperties() + { + if (static::$mysql_version < self::MYSQL_57) { + $this->markTestSkipped("MySQL < 5.7 does not support JSON fields."); + } + parent::testWriteProductProperties(); + } + + public function testListProducts() + { + parent::testListProducts(); + } + + public function testAddProducts() + { + if (static::$mysql_version < self::MYSQL_57) { + $this->markTestSkipped("MySQL < 5.7 does not support JSON fields."); + } + parent::testAddProducts(); + } + + public function testSoftDeleteProducts() + { + if (static::$mysql_version < self::MYSQL_57) { + $test = new API($this, static::$config); + $test->delete('/products/1'); + $test->expect('1'); + $test->get('/products?columns=id,deleted_at'); + $test->expect('{"products":{"columns":["id","deleted_at"],"records":[[1,"2013-12-11 11:10:09"]]}}'); + } else { + parent::testSoftDeleteProducts(); + } + } + } diff --git a/tests/PostgresqlTest.php b/tests/PostgresqlTest.php index bf2ea006..f30d2571 100644 --- a/tests/PostgresqlTest.php +++ b/tests/PostgresqlTest.php @@ -4,6 +4,9 @@ class PostgresqlTest extends PHP_CRUD_API_Test { + public static $gis_installed; + public static $pg_server_version; + public static function setUpBeforeClass() { static::setConfig('PostgreSQL'); @@ -21,8 +24,6 @@ public function seedDatabase() die("Configure database in 'config.php' before running tests.\n"); } - $fixture = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']).'.sql'; - $e = function ($v) { return str_replace(array('\'','\\'),array('\\\'','\\\\'),$v); }; $hostname = $e(static::$config['hostname']); $database = $e(static::$config['database']); @@ -36,16 +37,123 @@ public function seedDatabase() die("Connect failed: ". pg_last_error()); } - $queries = preg_split('/;\s*\n/', file_get_contents($fixture)); + static::$pg_server_version = pg_version()['server']; + $gisInstalled = self::isGisInstalled( + pg_fetch_all( + pg_query($db, "SELECT * FROM pg_extension;") + ) + ); + $seed_file = self::getSeedFile(); + $queries = preg_split('/;\s*\n/', file_get_contents($seed_file)); array_pop($queries); foreach ($queries as $i=>$query) { if (!pg_query($db, $query.';')) { $i++; - die("Loading '$fixture' failed on statemement #$i with error:\n".print_r( pg_last_error($db), true)."\n"); + die("Loading '$seed_file' failed on statemement #$i with error:\n".print_r( pg_last_error($db), true)."\n"); } } pg_close($db); } + + /** + * Gets the path to the seed file based on the version of Postgres and GIS extension + * + * @return string + */ + protected function getSeedFile() + { + $filepath = __DIR__.'/data/blog_'.strtolower(static::$config['dbengine']); + + if (version_compare(static::$pg_server_version, '9.4.0') >= 0 ) { + $filepath .= '_94'; + } elseif (version_compare(static::$pg_server_version, '9.2.0') >= 0 ) { + $filepath .= '_92'; + } else { + $filepath .= '_91'; + } + if (static::$gis_installed) { + $filepath .= '_gis'; + } + return $filepath.'.sql'; + } + + /** + * Determines whether the GIS extension is installed or not based on array of extensions. + * + * @return boolean + */ + protected function isGisInstalled($extensions = []) + { + static::$gis_installed = false; + if ($extensions) { + foreach ($extensions as $extension) { + if ($extension['extname'] === 'postgis') { + static::$gis_installed = true; + break; + } + } + } + return static::$gis_installed; + } + + public function testSpatialFilterWithin() + { + if (!static::$gis_installed) { + $this->markTestSkipped("Postgis not installed"); + } + parent::testSpatialFilterWithin(); + } + + public function testListProductsProperties() + { + if (version_compare(static::$pg_server_version, '9.2.0') < 0) { + $this->markTestSkipped("Postgres < 9.2.0 does not support JSON fields."); + } + parent::testListProductsProperties(); + } + + public function testReadProductProperties() + { + if (version_compare(static::$pg_server_version, '9.2.0') < 0) { + $this->markTestSkipped("Postgres < 9.2.0 does not support JSON fields."); + } + parent::testReadProductProperties(); + } + + public function testWriteProductProperties() + { + if (version_compare(static::$pg_server_version, '9.2.0') < 0) { + $this->markTestSkipped("Postgres < 9.2.0 does not support JSON fields."); + } + parent::testWriteProductProperties(); + } + + public function testListProducts() + { + parent::testListProducts(); + } + + public function testAddProducts() + { + if (version_compare(static::$pg_server_version, '9.2.0') < 0) { + $this->markTestSkipped("Postgres < 9.2.0 does not support JSON fields."); + } + parent::testAddProducts(); + } + + public function testSoftDeleteProducts() + { + if (version_compare(static::$pg_server_version, '9.2.0') < 0) { + $test = new API($this, static::$config); + $test->delete('/products/1'); + $test->expect('1'); + $test->get('/products?columns=id,deleted_at'); + $test->expect('{"products":{"columns":["id","deleted_at"],"records":[[1,"2013-12-11 11:10:09"]]}}'); + } else { + parent::testSoftDeleteProducts(); + } + } + } diff --git a/tests/data/blog_mysql_55.sql b/tests/data/blog_mysql_55.sql new file mode 100644 index 00000000..e882330f --- /dev/null +++ b/tests/data/blog_mysql_55.sql @@ -0,0 +1,148 @@ +-- Adminer 4.2.4 MySQL dump + +SET NAMES utf8; +SET time_zone = '+00:00'; +SET foreign_key_checks = 0; +SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; + +DROP TABLE IF EXISTS `categories`; +CREATE TABLE `categories` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `icon` blob NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `categories` (`id`, `name`, `icon`) VALUES +(1, 'announcement', NULL), +(2, 'article', NULL); + +DROP TABLE IF EXISTS `comments`; +CREATE TABLE `comments` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `post_id` int(11) NOT NULL, + `message` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `post_id` (`post_id`), + CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `comments` (`id`, `post_id`, `message`) VALUES +(1, 1, 'great'), +(2, 1, 'fantastic'), +(3, 2, 'thank you'), +(4, 2, 'awesome'); + +DROP TABLE IF EXISTS `posts`; +CREATE TABLE `posts` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `category_id` int(11) NOT NULL, + `content` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `category_id` (`category_id`), + KEY `user_id` (`user_id`), + CONSTRAINT `posts_ibfk_3` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`), + CONSTRAINT `posts_ibfk_4` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `posts` (`id`, `user_id`, `category_id`, `content`) VALUES +(1, 1, 1, 'blog started'), +(2, 1, 2, 'It works!'); + +DROP TABLE IF EXISTS `post_tags`; +CREATE TABLE `post_tags` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `post_id` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `post_id` (`post_id`), + KEY `tag_id` (`tag_id`), + CONSTRAINT `post_tags_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`), + CONSTRAINT `post_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `post_tags` (`id`, `post_id`, `tag_id`) VALUES +(1, 1, 1), +(2, 1, 2), +(3, 2, 1), +(4, 2, 2); + +DROP TABLE IF EXISTS `tags`; +CREATE TABLE `tags` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `tags` (`id`, `name`) VALUES +(1, 'funny'), +(2, 'important'); + +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `location` text NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `users` (`id`, `username`, `password`, `location`) VALUES +(1, 'user1', 'pass1', null), +(2, 'user2', 'pass2', null); + +DROP TABLE IF EXISTS `countries`; +CREATE TABLE `countries` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `countries` (`id`, `name`) VALUES +(1, 'Left'), +(2, 'Right'); + +DROP TABLE IF EXISTS `events`; +CREATE TABLE `events` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `datetime` datetime NOT NULL, + `visitors` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `events` (`id`, `name`, `datetime`, `visitors`) VALUES +(1, 'Launch', '2016-01-01 13:01:01', 0); + +DROP VIEW IF EXISTS `tag_usage`; +CREATE VIEW `tag_usage` AS select `name`, count(`name`) AS `count` from `tags`, `post_tags` where `tags`.`id` = `post_tags`.`tag_id` group by `name` order by `count` desc, `name`; + +DROP TABLE IF EXISTS `products`; +CREATE TABLE `products` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `price` decimal(10,2) NOT NULL, + `properties` text NOT NULL, + `created_at` datetime NOT NULL, + `deleted_at` datetime NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `products` (`id`, `name`, `price`, `properties`, `created_at`) VALUES +(1, 'Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +DROP TABLE IF EXISTS `barcodes`; +CREATE TABLE `barcodes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `product_id` int(11) NOT NULL, + `hex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, + `bin` varbinary(255) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `barcodes` (`id`, `product_id`, `hex`, `bin`) VALUES +(1, 1, '00ff01', UNHEX('00ff01')); + +-- 2016-11-05 13:11:47 diff --git a/tests/data/blog_mysql_56.sql b/tests/data/blog_mysql_56.sql new file mode 100644 index 00000000..8b8e0170 --- /dev/null +++ b/tests/data/blog_mysql_56.sql @@ -0,0 +1,149 @@ +-- Adminer 4.2.4 MySQL dump + +SET NAMES utf8; +SET time_zone = '+00:00'; +SET foreign_key_checks = 0; +SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; + +DROP TABLE IF EXISTS `categories`; +CREATE TABLE `categories` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `icon` blob NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `categories` (`id`, `name`, `icon`) VALUES +(1, 'announcement', NULL), +(2, 'article', NULL); + +DROP TABLE IF EXISTS `comments`; +CREATE TABLE `comments` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `post_id` int(11) NOT NULL, + `message` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `post_id` (`post_id`), + CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `comments` (`id`, `post_id`, `message`) VALUES +(1, 1, 'great'), +(2, 1, 'fantastic'), +(3, 2, 'thank you'), +(4, 2, 'awesome'); + +DROP TABLE IF EXISTS `posts`; +CREATE TABLE `posts` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `category_id` int(11) NOT NULL, + `content` varchar(255) NOT NULL, + PRIMARY KEY (`id`), + KEY `category_id` (`category_id`), + KEY `user_id` (`user_id`), + CONSTRAINT `posts_ibfk_3` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`), + CONSTRAINT `posts_ibfk_4` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `posts` (`id`, `user_id`, `category_id`, `content`) VALUES +(1, 1, 1, 'blog started'), +(2, 1, 2, 'It works!'); + +DROP TABLE IF EXISTS `post_tags`; +CREATE TABLE `post_tags` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `post_id` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `post_id` (`post_id`), + KEY `tag_id` (`tag_id`), + CONSTRAINT `post_tags_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`), + CONSTRAINT `post_tags_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `post_tags` (`id`, `post_id`, `tag_id`) VALUES +(1, 1, 1), +(2, 1, 2), +(3, 2, 1), +(4, 2, 2); + +DROP TABLE IF EXISTS `tags`; +CREATE TABLE `tags` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `tags` (`id`, `name`) VALUES +(1, 'funny'), +(2, 'important'); + +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `username` varchar(255) NOT NULL, + `password` varchar(255) NOT NULL, + `location` point NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `users` (`id`, `username`, `password`, `location`) VALUES +(1, 'user1', 'pass1', null), +(2, 'user2', 'pass2', null); + +DROP TABLE IF EXISTS `countries`; +CREATE TABLE `countries` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `shape` polygon NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `countries` (`id`, `name`, `shape`) VALUES +(1, 'Left', ST_GeomFromText('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')), +(2, 'Right', ST_GeomFromText('POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')); + +DROP TABLE IF EXISTS `events`; +CREATE TABLE `events` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `datetime` datetime NOT NULL, + `visitors` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `events` (`id`, `name`, `datetime`, `visitors`) VALUES +(1, 'Launch', '2016-01-01 13:01:01', 0); + +DROP VIEW IF EXISTS `tag_usage`; +CREATE VIEW `tag_usage` AS select `name`, count(`name`) AS `count` from `tags`, `post_tags` where `tags`.`id` = `post_tags`.`tag_id` group by `name` order by `count` desc, `name`; + +DROP TABLE IF EXISTS `products`; +CREATE TABLE `products` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `price` decimal(10,2) NOT NULL, + `properties` text NOT NULL, + `created_at` datetime NOT NULL, + `deleted_at` datetime NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `products` (`id`, `name`, `price`, `properties`, `created_at`) VALUES +(1, 'Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +DROP TABLE IF EXISTS `barcodes`; +CREATE TABLE `barcodes` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `product_id` int(11) NOT NULL, + `hex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, + `bin` varbinary(255) NOT NULL, + PRIMARY KEY (`id`), + CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; + +INSERT INTO `barcodes` (`id`, `product_id`, `hex`, `bin`) VALUES +(1, 1, '00ff01', UNHEX('00ff01')); + +-- 2016-11-05 13:11:47 diff --git a/tests/data/blog_mysql.sql b/tests/data/blog_mysql_57.sql similarity index 100% rename from tests/data/blog_mysql.sql rename to tests/data/blog_mysql_57.sql diff --git a/tests/data/blog_postgresql_91.sql b/tests/data/blog_postgresql_91.sql new file mode 100644 index 00000000..3d53802d --- /dev/null +++ b/tests/data/blog_postgresql_91.sql @@ -0,0 +1,383 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Drop everything +-- + +DROP TABLE IF EXISTS categories CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS post_tags CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS tags CASCADE; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS events CASCADE; +DROP VIEW IF EXISTS tag_usage; +DROP TABLE IF EXISTS products CASCADE; +DROP TABLE IF EXISTS barcodes CASCADE; + +-- +-- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE categories ( + id serial NOT NULL, + name character varying(255) NOT NULL, + icon bytea +); + + +-- +-- Name: comments; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE comments ( + id serial NOT NULL, + post_id integer NOT NULL, + message character varying(255) NOT NULL +); + + +-- +-- Name: post_tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE post_tags ( + id serial NOT NULL, + post_id integer NOT NULL, + tag_id integer NOT NULL +); + + +-- +-- Name: posts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE posts ( + id serial NOT NULL, + user_id integer NOT NULL, + category_id integer NOT NULL, + content character varying(255) NOT NULL +); + + +-- +-- Name: tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE tags ( + id serial NOT NULL, + name character varying(255) NOT NULL +); + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE users ( + id serial NOT NULL, + username character varying(255) NOT NULL, + password character varying(255) NOT NULL, + location text NULL +); + +-- +-- Name: events; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE events ( + id serial NOT NULL, + name character varying(255) NOT NULL, + datetime timestamp NOT NULL, + visitors integer NOT NULL +); + +-- +-- Name: tag_usage; Type: VIEW; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name"; + +-- +-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE products ( + id serial NOT NULL, + name character varying(255) NOT NULL, + price decimal(10,2) NOT NULL, + properties text NULL, + created_at timestamp NOT NULL, + deleted_at timestamp NULL +); + +-- +-- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE barcodes ( + id serial NOT NULL, + product_id integer NOT NULL, + hex character varying(255) NOT NULL, + bin bytea NOT NULL +); + +-- +-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "categories" ("name", "icon") VALUES +('announcement', NULL), +('article', NULL); + +-- +-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "comments" ("post_id", "message") VALUES +(1, 'great'), +(1, 'fantastic'), +(2, 'thank you'), +(2, 'awesome'); + +-- +-- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "post_tags" ("post_id", "tag_id") VALUES +(1, 1), +(1, 2), +(2, 1), +(2, 2); + +-- +-- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "posts" ("user_id", "category_id", "content") VALUES +(1, 1, 'blog started'), +(1, 2, 'It works!'); + +-- +-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "tags" ("name") VALUES +('funny'), +('important'); + +-- +-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "users" ("username", "password", "location") VALUES +('user1', 'pass1', NULL), +('user2', 'pass2', NULL); + +-- +-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "events" ("name", "datetime", "visitors") VALUES +('Launch', '2016-01-01 13:01:01', 0); + +-- +-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES +('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +-- +-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES +(1, '00ff01', E'\\x00ff01'); + +-- +-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY categories + ADD CONSTRAINT categories_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_post_id_tag_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_tag_id_key UNIQUE (post_id, tag_id); + + +-- +-- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_pkey PRIMARY KEY (id); + + +-- +-- Name: tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY tags + ADD CONSTRAINT tags_pkey PRIMARY KEY (id); + + +-- +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + +-- +-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + +-- +-- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX comments_post_id_idx ON comments USING btree (post_id); + + +-- +-- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_post_id_idx ON post_tags USING btree (post_id); + + +-- +-- Name: post_tags_tag_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_tag_id_idx ON post_tags USING btree (tag_id); + + +-- +-- Name: posts_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_category_id_idx ON posts USING btree (category_id); + + +-- +-- Name: posts_user_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_user_id_idx ON posts USING btree (user_id); + + +-- +-- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id); + + +-- +-- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES tags(id); + + +-- +-- Name: posts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id); + + +-- +-- Name: posts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); + + +-- +-- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id); + + +-- +-- PostgreSQL database dump complete +-- diff --git a/tests/data/blog_postgresql_91_gis.sql b/tests/data/blog_postgresql_91_gis.sql new file mode 100644 index 00000000..ecf4cced --- /dev/null +++ b/tests/data/blog_postgresql_91_gis.sql @@ -0,0 +1,416 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Drop everything +-- + +DROP TABLE IF EXISTS categories CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS post_tags CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS tags CASCADE; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS countries CASCADE; +DROP TABLE IF EXISTS events CASCADE; +DROP VIEW IF EXISTS tag_usage; +DROP TABLE IF EXISTS products CASCADE; +DROP TABLE IF EXISTS barcodes CASCADE; + +-- +-- Enables the Postgis extension +-- + +CREATE EXTENSION IF NOT EXISTS postgis; + +-- +-- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE categories ( + id serial NOT NULL, + name character varying(255) NOT NULL, + icon bytea +); + + +-- +-- Name: comments; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE comments ( + id serial NOT NULL, + post_id integer NOT NULL, + message character varying(255) NOT NULL +); + + +-- +-- Name: post_tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE post_tags ( + id serial NOT NULL, + post_id integer NOT NULL, + tag_id integer NOT NULL +); + + +-- +-- Name: posts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE posts ( + id serial NOT NULL, + user_id integer NOT NULL, + category_id integer NOT NULL, + content character varying(255) NOT NULL +); + + +-- +-- Name: tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE tags ( + id serial NOT NULL, + name character varying(255) NOT NULL +); + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE users ( + id serial NOT NULL, + username character varying(255) NOT NULL, + password character varying(255) NOT NULL, + location geometry NULL +); + +-- +-- Name: countries; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE countries ( + id serial NOT NULL, + name character varying(255) NOT NULL, + shape geometry NOT NULL +); + +-- +-- Name: events; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE events ( + id serial NOT NULL, + name character varying(255) NOT NULL, + datetime timestamp NOT NULL, + visitors integer NOT NULL +); + +-- +-- Name: tag_usage; Type: VIEW; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name"; + +-- +-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE products ( + id serial NOT NULL, + name character varying(255) NOT NULL, + price decimal(10,2) NOT NULL, + properties text NULL, + created_at timestamp NOT NULL, + deleted_at timestamp NULL +); + +-- +-- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE barcodes ( + id serial NOT NULL, + product_id integer NOT NULL, + hex character varying(255) NOT NULL, + bin bytea NOT NULL +); + +-- +-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "categories" ("name", "icon") VALUES +('announcement', NULL), +('article', NULL); + +-- +-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "comments" ("post_id", "message") VALUES +(1, 'great'), +(1, 'fantastic'), +(2, 'thank you'), +(2, 'awesome'); + +-- +-- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "post_tags" ("post_id", "tag_id") VALUES +(1, 1), +(1, 2), +(2, 1), +(2, 2); + +-- +-- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "posts" ("user_id", "category_id", "content") VALUES +(1, 1, 'blog started'), +(1, 2, 'It works!'); + +-- +-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "tags" ("name") VALUES +('funny'), +('important'); + +-- +-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "users" ("username", "password", "location") VALUES +('user1', 'pass1', NULL), +('user2', 'pass2', NULL); + +-- +-- Data for Name: countries; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "countries" ("name", "shape") VALUES +('Left', ST_GeomFromText('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')), +('Right', ST_GeomFromText('POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')); + +-- +-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "events" ("name", "datetime", "visitors") VALUES +('Launch', '2016-01-01 13:01:01', 0); + +-- +-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES +('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +-- +-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES +(1, '00ff01', E'\\x00ff01'); + +-- +-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY categories + ADD CONSTRAINT categories_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_post_id_tag_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_tag_id_key UNIQUE (post_id, tag_id); + + +-- +-- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_pkey PRIMARY KEY (id); + + +-- +-- Name: tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY tags + ADD CONSTRAINT tags_pkey PRIMARY KEY (id); + + +-- +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + +-- +-- Name: countries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY countries + ADD CONSTRAINT countries_pkey PRIMARY KEY (id); + + +-- +-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + +-- +-- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX comments_post_id_idx ON comments USING btree (post_id); + + +-- +-- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_post_id_idx ON post_tags USING btree (post_id); + + +-- +-- Name: post_tags_tag_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_tag_id_idx ON post_tags USING btree (tag_id); + + +-- +-- Name: posts_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_category_id_idx ON posts USING btree (category_id); + + +-- +-- Name: posts_user_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_user_id_idx ON posts USING btree (user_id); + + +-- +-- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id); + + +-- +-- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES tags(id); + + +-- +-- Name: posts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id); + + +-- +-- Name: posts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); + + +-- +-- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id); + + +-- +-- PostgreSQL database dump complete +-- diff --git a/tests/data/blog_postgresql_92.sql b/tests/data/blog_postgresql_92.sql new file mode 100644 index 00000000..b91d0c80 --- /dev/null +++ b/tests/data/blog_postgresql_92.sql @@ -0,0 +1,383 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Drop everything +-- + +DROP TABLE IF EXISTS categories CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS post_tags CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS tags CASCADE; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS events CASCADE; +DROP VIEW IF EXISTS tag_usage; +DROP TABLE IF EXISTS products CASCADE; +DROP TABLE IF EXISTS barcodes CASCADE; + +-- +-- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE categories ( + id serial NOT NULL, + name character varying(255) NOT NULL, + icon bytea +); + + +-- +-- Name: comments; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE comments ( + id serial NOT NULL, + post_id integer NOT NULL, + message character varying(255) NOT NULL +); + + +-- +-- Name: post_tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE post_tags ( + id serial NOT NULL, + post_id integer NOT NULL, + tag_id integer NOT NULL +); + + +-- +-- Name: posts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE posts ( + id serial NOT NULL, + user_id integer NOT NULL, + category_id integer NOT NULL, + content character varying(255) NOT NULL +); + + +-- +-- Name: tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE tags ( + id serial NOT NULL, + name character varying(255) NOT NULL +); + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE users ( + id serial NOT NULL, + username character varying(255) NOT NULL, + password character varying(255) NOT NULL, + location text NULL +); + +-- +-- Name: events; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE events ( + id serial NOT NULL, + name character varying(255) NOT NULL, + datetime timestamp NOT NULL, + visitors integer NOT NULL +); + +-- +-- Name: tag_usage; Type: VIEW; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name"; + +-- +-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE products ( + id serial NOT NULL, + name character varying(255) NOT NULL, + price decimal(10,2) NOT NULL, + properties json NOT NULL, + created_at timestamp NOT NULL, + deleted_at timestamp NULL +); + +-- +-- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE barcodes ( + id serial NOT NULL, + product_id integer NOT NULL, + hex character varying(255) NOT NULL, + bin bytea NOT NULL +); + +-- +-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "categories" ("name", "icon") VALUES +('announcement', NULL), +('article', NULL); + +-- +-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "comments" ("post_id", "message") VALUES +(1, 'great'), +(1, 'fantastic'), +(2, 'thank you'), +(2, 'awesome'); + +-- +-- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "post_tags" ("post_id", "tag_id") VALUES +(1, 1), +(1, 2), +(2, 1), +(2, 2); + +-- +-- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "posts" ("user_id", "category_id", "content") VALUES +(1, 1, 'blog started'), +(1, 2, 'It works!'); + +-- +-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "tags" ("name") VALUES +('funny'), +('important'); + +-- +-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "users" ("username", "password", "location") VALUES +('user1', 'pass1', NULL), +('user2', 'pass2', NULL); + +-- +-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "events" ("name", "datetime", "visitors") VALUES +('Launch', '2016-01-01 13:01:01', 0); + +-- +-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES +('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +-- +-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES +(1, '00ff01', E'\\x00ff01'); + +-- +-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY categories + ADD CONSTRAINT categories_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_post_id_tag_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_tag_id_key UNIQUE (post_id, tag_id); + + +-- +-- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_pkey PRIMARY KEY (id); + + +-- +-- Name: tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY tags + ADD CONSTRAINT tags_pkey PRIMARY KEY (id); + + +-- +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + +-- +-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + +-- +-- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX comments_post_id_idx ON comments USING btree (post_id); + + +-- +-- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_post_id_idx ON post_tags USING btree (post_id); + + +-- +-- Name: post_tags_tag_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_tag_id_idx ON post_tags USING btree (tag_id); + + +-- +-- Name: posts_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_category_id_idx ON posts USING btree (category_id); + + +-- +-- Name: posts_user_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_user_id_idx ON posts USING btree (user_id); + + +-- +-- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id); + + +-- +-- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES tags(id); + + +-- +-- Name: posts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id); + + +-- +-- Name: posts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); + + +-- +-- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id); + + +-- +-- PostgreSQL database dump complete +-- diff --git a/tests/data/blog_postgresql_92_gis.sql b/tests/data/blog_postgresql_92_gis.sql new file mode 100644 index 00000000..039fd80f --- /dev/null +++ b/tests/data/blog_postgresql_92_gis.sql @@ -0,0 +1,416 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Drop everything +-- + +DROP TABLE IF EXISTS categories CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS post_tags CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS tags CASCADE; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS countries CASCADE; +DROP TABLE IF EXISTS events CASCADE; +DROP VIEW IF EXISTS tag_usage; +DROP TABLE IF EXISTS products CASCADE; +DROP TABLE IF EXISTS barcodes CASCADE; + +-- +-- Enables the Postgis extension +-- + +CREATE EXTENSION IF NOT EXISTS postgis; + +-- +-- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE categories ( + id serial NOT NULL, + name character varying(255) NOT NULL, + icon bytea +); + + +-- +-- Name: comments; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE comments ( + id serial NOT NULL, + post_id integer NOT NULL, + message character varying(255) NOT NULL +); + + +-- +-- Name: post_tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE post_tags ( + id serial NOT NULL, + post_id integer NOT NULL, + tag_id integer NOT NULL +); + + +-- +-- Name: posts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE posts ( + id serial NOT NULL, + user_id integer NOT NULL, + category_id integer NOT NULL, + content character varying(255) NOT NULL +); + + +-- +-- Name: tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE tags ( + id serial NOT NULL, + name character varying(255) NOT NULL +); + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE users ( + id serial NOT NULL, + username character varying(255) NOT NULL, + password character varying(255) NOT NULL, + location geometry NULL +); + +-- +-- Name: countries; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE countries ( + id serial NOT NULL, + name character varying(255) NOT NULL, + shape geometry NOT NULL +); + +-- +-- Name: events; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE events ( + id serial NOT NULL, + name character varying(255) NOT NULL, + datetime timestamp NOT NULL, + visitors integer NOT NULL +); + +-- +-- Name: tag_usage; Type: VIEW; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name"; + +-- +-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE products ( + id serial NOT NULL, + name character varying(255) NOT NULL, + price decimal(10,2) NOT NULL, + properties json NOT NULL, + created_at timestamp NOT NULL, + deleted_at timestamp NULL +); + +-- +-- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE barcodes ( + id serial NOT NULL, + product_id integer NOT NULL, + hex character varying(255) NOT NULL, + bin bytea NOT NULL +); + +-- +-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "categories" ("name", "icon") VALUES +('announcement', NULL), +('article', NULL); + +-- +-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "comments" ("post_id", "message") VALUES +(1, 'great'), +(1, 'fantastic'), +(2, 'thank you'), +(2, 'awesome'); + +-- +-- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "post_tags" ("post_id", "tag_id") VALUES +(1, 1), +(1, 2), +(2, 1), +(2, 2); + +-- +-- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "posts" ("user_id", "category_id", "content") VALUES +(1, 1, 'blog started'), +(1, 2, 'It works!'); + +-- +-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "tags" ("name") VALUES +('funny'), +('important'); + +-- +-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "users" ("username", "password", "location") VALUES +('user1', 'pass1', NULL), +('user2', 'pass2', NULL); + +-- +-- Data for Name: countries; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "countries" ("name", "shape") VALUES +('Left', ST_GeomFromText('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')), +('Right', ST_GeomFromText('POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))')); + +-- +-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "events" ("name", "datetime", "visitors") VALUES +('Launch', '2016-01-01 13:01:01', 0); + +-- +-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES +('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +-- +-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES +(1, '00ff01', E'\\x00ff01'); + +-- +-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY categories + ADD CONSTRAINT categories_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_post_id_tag_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_tag_id_key UNIQUE (post_id, tag_id); + + +-- +-- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_pkey PRIMARY KEY (id); + + +-- +-- Name: tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY tags + ADD CONSTRAINT tags_pkey PRIMARY KEY (id); + + +-- +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + +-- +-- Name: countries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY countries + ADD CONSTRAINT countries_pkey PRIMARY KEY (id); + + +-- +-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + +-- +-- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX comments_post_id_idx ON comments USING btree (post_id); + + +-- +-- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_post_id_idx ON post_tags USING btree (post_id); + + +-- +-- Name: post_tags_tag_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_tag_id_idx ON post_tags USING btree (tag_id); + + +-- +-- Name: posts_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_category_id_idx ON posts USING btree (category_id); + + +-- +-- Name: posts_user_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_user_id_idx ON posts USING btree (user_id); + + +-- +-- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id); + + +-- +-- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES tags(id); + + +-- +-- Name: posts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id); + + +-- +-- Name: posts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); + + +-- +-- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id); + + +-- +-- PostgreSQL database dump complete +-- diff --git a/tests/data/blog_postgresql_94.sql b/tests/data/blog_postgresql_94.sql new file mode 100644 index 00000000..68b9c6b8 --- /dev/null +++ b/tests/data/blog_postgresql_94.sql @@ -0,0 +1,383 @@ +-- +-- PostgreSQL database dump +-- + +SET statement_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SET check_function_bodies = false; +SET client_min_messages = warning; + +SET search_path = public, pg_catalog; + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Drop everything +-- + +DROP TABLE IF EXISTS categories CASCADE; +DROP TABLE IF EXISTS comments CASCADE; +DROP TABLE IF EXISTS post_tags CASCADE; +DROP TABLE IF EXISTS posts CASCADE; +DROP TABLE IF EXISTS tags CASCADE; +DROP TABLE IF EXISTS users CASCADE; +DROP TABLE IF EXISTS events CASCADE; +DROP VIEW IF EXISTS tag_usage; +DROP TABLE IF EXISTS products CASCADE; +DROP TABLE IF EXISTS barcodes CASCADE; + +-- +-- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE categories ( + id serial NOT NULL, + name character varying(255) NOT NULL, + icon bytea +); + + +-- +-- Name: comments; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE comments ( + id serial NOT NULL, + post_id integer NOT NULL, + message character varying(255) NOT NULL +); + + +-- +-- Name: post_tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE post_tags ( + id serial NOT NULL, + post_id integer NOT NULL, + tag_id integer NOT NULL +); + + +-- +-- Name: posts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE posts ( + id serial NOT NULL, + user_id integer NOT NULL, + category_id integer NOT NULL, + content character varying(255) NOT NULL +); + + +-- +-- Name: tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE tags ( + id serial NOT NULL, + name character varying(255) NOT NULL +); + + +-- +-- Name: users; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE users ( + id serial NOT NULL, + username character varying(255) NOT NULL, + password character varying(255) NOT NULL, + location text NULL +); + +-- +-- Name: events; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE events ( + id serial NOT NULL, + name character varying(255) NOT NULL, + datetime timestamp NOT NULL, + visitors integer NOT NULL +); + +-- +-- Name: tag_usage; Type: VIEW; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name"; + +-- +-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE products ( + id serial NOT NULL, + name character varying(255) NOT NULL, + price decimal(10,2) NOT NULL, + properties jsonb NOT NULL, + created_at timestamp NOT NULL, + deleted_at timestamp NULL +); + +-- +-- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE TABLE barcodes ( + id serial NOT NULL, + product_id integer NOT NULL, + hex character varying(255) NOT NULL, + bin bytea NOT NULL +); + +-- +-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "categories" ("name", "icon") VALUES +('announcement', NULL), +('article', NULL); + +-- +-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "comments" ("post_id", "message") VALUES +(1, 'great'), +(1, 'fantastic'), +(2, 'thank you'), +(2, 'awesome'); + +-- +-- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "post_tags" ("post_id", "tag_id") VALUES +(1, 1), +(1, 2), +(2, 1), +(2, 2); + +-- +-- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "posts" ("user_id", "category_id", "content") VALUES +(1, 1, 'blog started'), +(1, 2, 'It works!'); + +-- +-- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "tags" ("name") VALUES +('funny'), +('important'); + +-- +-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "users" ("username", "password", "location") VALUES +('user1', 'pass1', NULL), +('user2', 'pass2', NULL); + +-- +-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "events" ("name", "datetime", "visitors") VALUES +('Launch', '2016-01-01 13:01:01', 0); + +-- +-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES +('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01'); + +-- +-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres +-- + +INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES +(1, '00ff01', E'\\x00ff01'); + +-- +-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY categories + ADD CONSTRAINT categories_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_pkey PRIMARY KEY (id); + + +-- +-- Name: post_tags_post_id_tag_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_tag_id_key UNIQUE (post_id, tag_id); + + +-- +-- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_pkey PRIMARY KEY (id); + + +-- +-- Name: tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY tags + ADD CONSTRAINT tags_pkey PRIMARY KEY (id); + + +-- +-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY users + ADD CONSTRAINT users_pkey PRIMARY KEY (id); + +-- +-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY events + ADD CONSTRAINT events_pkey PRIMARY KEY (id); + + +-- +-- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY products + ADD CONSTRAINT products_pkey PRIMARY KEY (id); + + +-- +-- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace: +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id); + + +-- +-- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX comments_post_id_idx ON comments USING btree (post_id); + + +-- +-- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_post_id_idx ON post_tags USING btree (post_id); + + +-- +-- Name: post_tags_tag_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX post_tags_tag_id_idx ON post_tags USING btree (tag_id); + + +-- +-- Name: posts_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_category_id_idx ON posts USING btree (category_id); + + +-- +-- Name: posts_user_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX posts_user_id_idx ON posts USING btree (user_id); + + +-- +-- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace: +-- + +CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id); + + +-- +-- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY comments + ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id); + + +-- +-- Name: post_tags_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY post_tags + ADD CONSTRAINT post_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES tags(id); + + +-- +-- Name: posts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id); + + +-- +-- Name: posts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY posts + ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id); + + +-- +-- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY barcodes + ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id); + + +-- +-- PostgreSQL database dump complete +-- diff --git a/tests/data/blog_postgresql.sql b/tests/data/blog_postgresql_94_gis.sql similarity index 100% rename from tests/data/blog_postgresql.sql rename to tests/data/blog_postgresql_94_gis.sql