From 91b38cb2a93007862496ec9e7a8fff4a399af1ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ad=C3=A1mek?= Date: Thu, 20 Aug 2020 15:33:26 +0200 Subject: [PATCH] fix(schema): do not create indexes for each composite PK Closes: #760 --- packages/knex/src/schema/SchemaGenerator.ts | 2 +- .../EntityGenerator.test.ts.snap | 37 ++-- .../SchemaGenerator.test.ts.snap | 21 -- tests/issues/GH529.test.ts | 6 + tests/issues/__snapshots__/GH529.test.ts.snap | 23 ++ tests/mysql-schema.sql | 205 +++++++++--------- tests/postgre-schema.sql | 93 ++++---- tests/sqlite-schema.sql | 39 ++-- 8 files changed, 210 insertions(+), 216 deletions(-) create mode 100644 tests/issues/__snapshots__/GH529.test.ts.snap diff --git a/packages/knex/src/schema/SchemaGenerator.ts b/packages/knex/src/schema/SchemaGenerator.ts index 087a37a653c7..218d78ac8ce5 100644 --- a/packages/knex/src/schema/SchemaGenerator.ts +++ b/packages/knex/src/schema/SchemaGenerator.ts @@ -373,7 +373,7 @@ export class SchemaGenerator { const nullable = (alter && this.platform.requiresNullableForAlteringColumn()) || prop.nullable!; const sameNullable = alter && 'sameNullable' in alter && alter.sameNullable; const indexed = 'index' in prop ? prop.index : (prop.reference !== ReferenceType.SCALAR && this.helper.indexForeignKeys()); - const index = (indexed || (prop.primary && meta.compositePK)) && !(alter?.sameIndex); + const index = indexed && !alter?.sameIndex; const indexName = this.getIndexName(meta, prop, false, columnName); const uniqueName = this.getIndexName(meta, prop, true, columnName); const sameDefault = alter && 'sameDefault' in alter ? alter.sameDefault : !prop.defaultRaw; diff --git a/tests/__snapshots__/EntityGenerator.test.ts.snap b/tests/__snapshots__/EntityGenerator.test.ts.snap index 1e2a0e486650..48a4dc381636 100644 --- a/tests/__snapshots__/EntityGenerator.test.ts.snap +++ b/tests/__snapshots__/EntityGenerator.test.ts.snap @@ -117,12 +117,6 @@ export class BaseUser2 { @Property({ columnType: 'enum' }) type!: string; - @Property({ nullable: true }) - employeeProp?: number; - - @Property({ length: 255, nullable: true }) - managerProp?: string; - @Property({ length: 255, nullable: true }) ownerProp?: string; @@ -132,6 +126,12 @@ export class BaseUser2 { @OneToOne({ entity: () => BaseUser2, nullable: true, index: 'base_user2_favourite_manager_id_index', unique: 'base_user2_favourite_manager_id_unique' }) favouriteManager?: BaseUser2; + @Property({ nullable: true }) + employeeProp?: number; + + @Property({ length: 255, nullable: true }) + managerProp?: string; + } ", "import { Cascade, Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; @@ -254,13 +254,12 @@ export class CarOwner2 { } ", - "import { Entity, Index, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Test2 } from './Test2'; @Entity() export class Configuration2 { - @Index({ name: 'configuration2_property_index' }) @PrimaryKey({ length: 255 }) property!: string; @@ -440,17 +439,15 @@ export class Test2 { } ", - "import { Entity, Index, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Entity, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Car2 } from './Car2'; @Entity() export class User2 { - @Index({ name: 'user2_first_name_index' }) @PrimaryKey({ length: 100 }) firstName!: string; - @Index({ name: 'user2_last_name_index' }) @PrimaryKey({ length: 100 }) lastName!: string; @@ -679,17 +676,16 @@ export class BookToTagUnordered { } ", - "import { Entity, Index, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; + "import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; import { Test2 } from './Test2'; @Entity() export class Configuration2 { - @Index({ name: 'configuration2_property_index' }) @PrimaryKey({ length: 255 }) property!: string; - @ManyToOne({ entity: () => Test2, primary: true, index: 'configuration2_test_id_index' }) + @ManyToOne({ entity: () => Test2, primary: true }) test!: Test2; @Property({ length: 255 }) @@ -752,10 +748,10 @@ import { FooBaz2 } from './FooBaz2'; @Entity() export class FooParam2 { - @ManyToOne({ entity: () => FooBar2, primary: true, index: 'foo_param2_bar_id_index' }) + @ManyToOne({ entity: () => FooBar2, primary: true }) bar!: FooBar2; - @ManyToOne({ entity: () => FooBaz2, primary: true, index: 'foo_param2_baz_id_index' }) + @ManyToOne({ entity: () => FooBaz2, primary: true }) baz!: FooBaz2; @Property({ length: 255 }) @@ -881,13 +877,13 @@ export class Author3 { @Property() termsAccepted!: number; - @Property({ nullable: true }) + @Property({ columnType: 'text', nullable: true }) identities?: string; - @Property({ columnType: 'date', nullable: true }) + @Property({ columnType: 'date(3)', nullable: true }) born?: string; - @Property({ columnType: 'time', nullable: true }) + @Property({ columnType: 'time(3)', nullable: true }) bornTime?: string; @ManyToOne({ entity: () => Book3, nullable: true, index: 'author3_favourite_book_id_index' }) @@ -914,9 +910,6 @@ export class Book3 { @Property({ default: '' }) title!: string; - @Property({ nullable: true, default: 'lol' }) - foo?: string; - @ManyToOne({ entity: () => Author3, nullable: true, index: 'book3_author_id_index' }) author?: Author3; diff --git a/tests/__snapshots__/SchemaGenerator.test.ts.snap b/tests/__snapshots__/SchemaGenerator.test.ts.snap index 50df5d0dac0d..f37b6f56805e 100644 --- a/tests/__snapshots__/SchemaGenerator.test.ts.snap +++ b/tests/__snapshots__/SchemaGenerator.test.ts.snap @@ -32,8 +32,6 @@ create table \`car_owner2\` (\`id\` int unsigned not null auto_increment primary alter table \`car_owner2\` add index \`car_owner2_car_name_car_year_index\`(\`car_name\`, \`car_year\`); create table \`user2\` (\`first_name\` varchar(100) not null, \`last_name\` varchar(100) not null, \`foo\` int(11) null, \`favourite_car_name\` varchar(100) null, \`favourite_car_year\` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; -alter table \`user2\` add index \`user2_first_name_index\`(\`first_name\`); -alter table \`user2\` add index \`user2_last_name_index\`(\`last_name\`); alter table \`user2\` add unique \`user2_favourite_car_name_unique\`(\`favourite_car_name\`); alter table \`user2\` add unique \`user2_favourite_car_year_unique\`(\`favourite_car_year\`); alter table \`user2\` add primary key \`user2_pkey\`(\`first_name\`, \`last_name\`); @@ -79,7 +77,6 @@ alter table \`test2\` add index \`test2_book_uuid_pk_index\`(\`book_uuid_pk\`); alter table \`test2\` add unique \`test2_book_uuid_pk_unique\`(\`book_uuid_pk\`); create table \`configuration2\` (\`property\` varchar(255) not null, \`test_id\` int(11) unsigned not null, \`value\` varchar(255) not null) default character set utf8mb4 engine = InnoDB; -alter table \`configuration2\` add index \`configuration2_property_index\`(\`property\`); alter table \`configuration2\` add index \`configuration2_test_id_index\`(\`test_id\`); alter table \`configuration2\` add primary key \`configuration2_pkey\`(\`property\`, \`test_id\`); @@ -249,8 +246,6 @@ create table \`car_owner2\` (\`id\` int unsigned not null auto_increment primary alter table \`car_owner2\` add index \`car_owner2_car_name_car_year_index\`(\`car_name\`, \`car_year\`); create table \`user2\` (\`first_name\` varchar(100) not null, \`last_name\` varchar(100) not null, \`foo\` int(11) null, \`favourite_car_name\` varchar(100) null, \`favourite_car_year\` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; -alter table \`user2\` add index \`user2_first_name_index\`(\`first_name\`); -alter table \`user2\` add index \`user2_last_name_index\`(\`last_name\`); alter table \`user2\` add unique \`user2_favourite_car_name_unique\`(\`favourite_car_name\`); alter table \`user2\` add unique \`user2_favourite_car_year_unique\`(\`favourite_car_year\`); alter table \`user2\` add primary key \`user2_pkey\`(\`first_name\`, \`last_name\`); @@ -296,7 +291,6 @@ alter table \`test2\` add index \`test2_book_uuid_pk_index\`(\`book_uuid_pk\`); alter table \`test2\` add unique \`test2_book_uuid_pk_unique\`(\`book_uuid_pk\`); create table \`configuration2\` (\`property\` varchar(255) not null, \`test_id\` int(11) unsigned not null, \`value\` varchar(255) not null) default character set utf8mb4 engine = InnoDB; -alter table \`configuration2\` add index \`configuration2_property_index\`(\`property\`); alter table \`configuration2\` add index \`configuration2_test_id_index\`(\`test_id\`); alter table \`configuration2\` add primary key \`configuration2_pkey\`(\`property\`, \`test_id\`); @@ -408,8 +402,6 @@ alter table \\"foo_bar2\\" add constraint \\"foo_bar2_baz_id_unique\\" unique (\ alter table \\"foo_bar2\\" add constraint \\"foo_bar2_foo_bar_id_unique\\" unique (\\"foo_bar_id\\"); create table \\"foo_param2\\" (\\"bar_id\\" int4 not null, \\"baz_id\\" int4 not null, \\"value\\" varchar(255) not null); -create index \\"foo_param2_bar_id_index\\" on \\"foo_param2\\" (\\"bar_id\\"); -create index \\"foo_param2_baz_id_index\\" on \\"foo_param2\\" (\\"baz_id\\"); alter table \\"foo_param2\\" add constraint \\"foo_param2_pkey\\" primary key (\\"bar_id\\", \\"baz_id\\"); create table \\"publisher2\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) not null, \\"type\\" text check (\\"type\\" in ('local', 'global')) not null, \\"type2\\" text check (\\"type2\\" in ('LOCAL', 'GLOBAL')) not null, \\"enum1\\" int2 null, \\"enum2\\" int2 null, \\"enum3\\" int2 null, \\"enum4\\" text check (\\"enum4\\" in ('a', 'b', 'c')) null); @@ -439,8 +431,6 @@ create table \\"test2\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) n alter table \\"test2\\" add constraint \\"test2_book_uuid_pk_unique\\" unique (\\"book_uuid_pk\\"); create table \\"configuration2\\" (\\"property\\" varchar(255) not null, \\"test_id\\" int4 not null, \\"value\\" varchar(255) not null); -create index \\"configuration2_property_index\\" on \\"configuration2\\" (\\"property\\"); -create index \\"configuration2_test_id_index\\" on \\"configuration2\\" (\\"test_id\\"); alter table \\"configuration2\\" add constraint \\"configuration2_pkey\\" primary key (\\"property\\", \\"test_id\\"); create table \\"publisher2_tests\\" (\\"id\\" serial primary key, \\"publisher2_id\\" int4 not null, \\"test2_id\\" int4 not null); @@ -549,8 +539,6 @@ alter table \\"foo_bar2\\" add constraint \\"foo_bar2_baz_id_unique\\" unique (\ alter table \\"foo_bar2\\" add constraint \\"foo_bar2_foo_bar_id_unique\\" unique (\\"foo_bar_id\\"); create table \\"foo_param2\\" (\\"bar_id\\" int4 not null, \\"baz_id\\" int4 not null, \\"value\\" varchar(255) not null); -create index \\"foo_param2_bar_id_index\\" on \\"foo_param2\\" (\\"bar_id\\"); -create index \\"foo_param2_baz_id_index\\" on \\"foo_param2\\" (\\"baz_id\\"); alter table \\"foo_param2\\" add constraint \\"foo_param2_pkey\\" primary key (\\"bar_id\\", \\"baz_id\\"); create table \\"publisher2\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) not null, \\"type\\" text check (\\"type\\" in ('local', 'global')) not null, \\"type2\\" text check (\\"type2\\" in ('LOCAL', 'GLOBAL')) not null, \\"enum1\\" int2 null, \\"enum2\\" int2 null, \\"enum3\\" int2 null, \\"enum4\\" text check (\\"enum4\\" in ('a', 'b', 'c')) null); @@ -580,8 +568,6 @@ create table \\"test2\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) n alter table \\"test2\\" add constraint \\"test2_book_uuid_pk_unique\\" unique (\\"book_uuid_pk\\"); create table \\"configuration2\\" (\\"property\\" varchar(255) not null, \\"test_id\\" int4 not null, \\"value\\" varchar(255) not null); -create index \\"configuration2_property_index\\" on \\"configuration2\\" (\\"property\\"); -create index \\"configuration2_test_id_index\\" on \\"configuration2\\" (\\"test_id\\"); alter table \\"configuration2\\" add constraint \\"configuration2_pkey\\" primary key (\\"property\\", \\"test_id\\"); create table \\"publisher2_tests\\" (\\"id\\" serial primary key, \\"publisher2_id\\" int4 not null, \\"test2_id\\" int4 not null); @@ -935,8 +921,6 @@ create table \`car_owner2\` (\`id\` int unsigned not null auto_increment primary alter table \`car_owner2\` add index \`car_owner2_car_name_car_year_index\`(\`car_name\`, \`car_year\`); create table \`user2\` (\`first_name\` varchar(100) not null, \`last_name\` varchar(100) not null, \`foo\` int(11) null, \`favourite_car_name\` varchar(100) null, \`favourite_car_year\` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; -alter table \`user2\` add index \`user2_first_name_index\`(\`first_name\`); -alter table \`user2\` add index \`user2_last_name_index\`(\`last_name\`); alter table \`user2\` add unique \`user2_favourite_car_name_unique\`(\`favourite_car_name\`); alter table \`user2\` add unique \`user2_favourite_car_year_unique\`(\`favourite_car_year\`); alter table \`user2\` add primary key \`user2_pkey\`(\`first_name\`, \`last_name\`); @@ -982,7 +966,6 @@ alter table \`test2\` add index \`test2_book_uuid_pk_index\`(\`book_uuid_pk\`); alter table \`test2\` add unique \`test2_book_uuid_pk_unique\`(\`book_uuid_pk\`); create table \`configuration2\` (\`property\` varchar(255) not null, \`test_id\` int(11) unsigned not null, \`value\` varchar(255) not null) default character set utf8mb4 engine = InnoDB; -alter table \`configuration2\` add index \`configuration2_property_index\`(\`property\`); alter table \`configuration2\` add index \`configuration2_test_id_index\`(\`test_id\`); alter table \`configuration2\` add primary key \`configuration2_pkey\`(\`property\`, \`test_id\`); @@ -1078,8 +1061,6 @@ alter table \\"foo_bar2\\" add constraint \\"foo_bar2_baz_id_unique\\" unique (\ alter table \\"foo_bar2\\" add constraint \\"foo_bar2_foo_bar_id_unique\\" unique (\\"foo_bar_id\\"); create table \\"foo_param2\\" (\\"bar_id\\" int4 not null, \\"baz_id\\" int4 not null, \\"value\\" varchar(255) not null); -create index \\"foo_param2_bar_id_index\\" on \\"foo_param2\\" (\\"bar_id\\"); -create index \\"foo_param2_baz_id_index\\" on \\"foo_param2\\" (\\"baz_id\\"); alter table \\"foo_param2\\" add constraint \\"foo_param2_pkey\\" primary key (\\"bar_id\\", \\"baz_id\\"); create table \\"publisher2\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) not null, \\"type\\" text check (\\"type\\" in ('local', 'global')) not null, \\"type2\\" text check (\\"type2\\" in ('LOCAL', 'GLOBAL')) not null, \\"enum1\\" int2 null, \\"enum2\\" int2 null, \\"enum3\\" int2 null, \\"enum4\\" text check (\\"enum4\\" in ('a', 'b', 'c')) null); @@ -1109,8 +1090,6 @@ create table \\"test2\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) n alter table \\"test2\\" add constraint \\"test2_book_uuid_pk_unique\\" unique (\\"book_uuid_pk\\"); create table \\"configuration2\\" (\\"property\\" varchar(255) not null, \\"test_id\\" int4 not null, \\"value\\" varchar(255) not null); -create index \\"configuration2_property_index\\" on \\"configuration2\\" (\\"property\\"); -create index \\"configuration2_test_id_index\\" on \\"configuration2\\" (\\"test_id\\"); alter table \\"configuration2\\" add constraint \\"configuration2_pkey\\" primary key (\\"property\\", \\"test_id\\"); create table \\"publisher2_tests\\" (\\"id\\" serial primary key, \\"publisher2_id\\" int4 not null, \\"test2_id\\" int4 not null); diff --git a/tests/issues/GH529.test.ts b/tests/issues/GH529.test.ts index 9d5e9cd9a55c..384cc6d85175 100644 --- a/tests/issues/GH529.test.ts +++ b/tests/issues/GH529.test.ts @@ -117,4 +117,10 @@ describe('GH issue 529', () => { await o.items.init(); expect(o.items.getItems()).toHaveLength(3); }); + + test(`GH issue 760`, async () => { + const sql = await orm.getSchemaGenerator().getCreateSchemaSQL(); + expect(sql).toMatchSnapshot(); + }); + }); diff --git a/tests/issues/__snapshots__/GH529.test.ts.snap b/tests/issues/__snapshots__/GH529.test.ts.snap new file mode 100644 index 000000000000..0b012f209cce --- /dev/null +++ b/tests/issues/__snapshots__/GH529.test.ts.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`GH issue 529 GH issue 760 1`] = ` +"set names 'utf8'; +set session_replication_role = 'replica'; + +create table \\"product\\" (\\"id\\" serial primary key, \\"name\\" varchar(255) not null, \\"current_price\\" int4 not null); + +create table \\"customer\\" (\\"id\\" serial primary key); + +create table \\"order\\" (\\"id\\" serial primary key, \\"customer_id\\" int4 not null, \\"paid\\" jsonb not null, \\"shipped\\" jsonb not null, \\"created\\" timestamptz(0) not null); + +create table \\"order_item\\" (\\"order_id\\" int4 not null, \\"product_id\\" int4 not null, \\"amount\\" int4 not null, \\"offered_price\\" int4 not null); +alter table \\"order_item\\" add constraint \\"order_item_pkey\\" primary key (\\"order_id\\", \\"product_id\\"); + +alter table \\"order\\" add constraint \\"order_customer_id_foreign\\" foreign key (\\"customer_id\\") references \\"customer\\" (\\"id\\") on update cascade; + +alter table \\"order_item\\" add constraint \\"order_item_order_id_foreign\\" foreign key (\\"order_id\\") references \\"order\\" (\\"id\\") on update cascade; +alter table \\"order_item\\" add constraint \\"order_item_product_id_foreign\\" foreign key (\\"product_id\\") references \\"product\\" (\\"id\\") on update cascade; + +set session_replication_role = 'origin'; +" +`; diff --git a/tests/mysql-schema.sql b/tests/mysql-schema.sql index 7b45f3496973..8dc84a950f92 100644 --- a/tests/mysql-schema.sql +++ b/tests/mysql-schema.sql @@ -1,67 +1,44 @@ set names utf8mb4; set foreign_key_checks = 0; -drop table if exists `author2`; drop table if exists `address2`; -drop table if exists `book2`; -drop table if exists `book_tag2`; -drop table if exists `publisher2`; -drop table if exists `test2`; -drop table if exists `foo_bar2`; -drop table if exists `foo_baz2`; -drop table if exists `foo_param2`; -drop table if exists `configuration2`; -drop table if exists `car2`; -drop table if exists `dummy2`; -drop table if exists `car_owner2`; -drop table if exists `user2`; -drop table if exists `base_user2`; -drop table if exists `author_to_friend`; drop table if exists `author2_following`; +drop table if exists `author_to_friend`; +drop table if exists `book_to_tag_unordered`; drop table if exists `book2_tags`; drop table if exists `publisher2_tests`; +drop table if exists `configuration2`; +drop table if exists `test2`; +drop table if exists `book2`; +drop table if exists `author2`; +drop table if exists `base_user2`; +drop table if exists `book_tag2`; drop table if exists `user2_cars`; -drop table if exists `book_to_tag_unordered`; +drop table if exists `user2_sandwiches`; +drop table if exists `user2`; +drop table if exists `car_owner2`; +drop table if exists `car2`; +drop table if exists `dummy2`; +drop table if exists `foo_param2`; +drop table if exists `foo_bar2`; +drop table if exists `foo_baz2`; +drop table if exists `publisher2`; +drop table if exists `sandwich`; drop table if exists `new_table`; drop table if exists `author2_to_author2`; drop table if exists `book2_to_book_tag2`; drop table if exists `publisher2_to_test2`; drop table if exists `user2_to_car2`; -drop table if exists `sandwich`; -drop table if exists `user2_sandwiches`; - -create table `author2` (`id` int unsigned not null auto_increment primary key, `created_at` datetime(3) not null default current_timestamp(3), `updated_at` datetime(3) not null default current_timestamp(3), `name` varchar(255) not null, `email` varchar(255) not null, `age` int(11) null default null, `terms_accepted` tinyint(1) not null default false, `optional` tinyint(1) null, `identities` text null, `born` date null, `born_time` time null, `favourite_book_uuid_pk` varchar(36) null, `favourite_author_id` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; -alter table `author2` add index `custom_email_index_name`(`email`); -alter table `author2` add unique `custom_email_unique_name`(`email`); -alter table `author2` add index `author2_terms_accepted_index`(`terms_accepted`); -alter table `author2` add index `author2_born_index`(`born`); -alter table `author2` add index `born_time_idx`(`born_time`); -alter table `author2` add index `author2_favourite_book_uuid_pk_index`(`favourite_book_uuid_pk`); -alter table `author2` add index `author2_favourite_author_id_index`(`favourite_author_id`); -alter table `author2` add index `custom_idx_name_123`(`name`); -alter table `author2` add index `author2_name_age_index`(`name`, `age`); -alter table `author2` add unique `author2_name_email_unique`(`name`, `email`); - -create table `address2` (`author_id` int(11) unsigned not null, `value` varchar(255) not null) default character set utf8mb4 engine = InnoDB; -alter table `address2` add primary key `address2_pkey`(`author_id`); -alter table `address2` add index `address2_author_id_index`(`author_id`); -alter table `address2` add unique `address2_author_id_unique`(`author_id`); -create table `book2` (`uuid_pk` varchar(36) not null, `created_at` datetime(3) not null default current_timestamp(3), `title` varchar(255) null default '', `perex` text null, `price` float null, `double` double null, `meta` json null, `author_id` int(11) unsigned not null, `publisher_id` int(11) unsigned null, `foo` varchar(255) null default 'lol') default character set utf8mb4 engine = InnoDB; -alter table `book2` add primary key `book2_pkey`(`uuid_pk`); -alter table `book2` add index `book2_author_id_index`(`author_id`); -alter table `book2` add index `book2_publisher_id_index`(`publisher_id`); +set names utf8mb4; +set foreign_key_checks = 0; -create table `book_tag2` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(50) not null) default character set utf8mb4 engine = InnoDB; +create table `sandwich` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `price` int(11) not null) default character set utf8mb4 engine = InnoDB; create table `publisher2` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `type` enum('local', 'global') not null, `type2` enum('LOCAL', 'GLOBAL') not null, `enum1` tinyint null, `enum2` tinyint null, `enum3` tinyint null, `enum4` enum('a', 'b', 'c') null) default character set utf8mb4 engine = InnoDB; -create table `test2` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) null, `book_uuid_pk` varchar(36) null, `version` int(11) not null default 1, `foo___bar` int(11) unsigned null, `foo___baz` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; -alter table `test2` add index `test2_book_uuid_pk_index`(`book_uuid_pk`); -alter table `test2` add unique `test2_book_uuid_pk_unique`(`book_uuid_pk`); -alter table `test2` add index `test2_foo___bar_index`(`foo___bar`); -alter table `test2` add unique `test2_foo___bar_unique`(`foo___bar`); +create table `foo_baz2` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `version` datetime(3) not null default current_timestamp(3)) default character set utf8mb4 engine = InnoDB; create table `foo_bar2` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `baz_id` int(11) unsigned null, `foo_bar_id` int(11) unsigned null, `version` datetime not null default current_timestamp, `blob` blob null, `array` text null, `object` json null) default character set utf8mb4 engine = InnoDB; alter table `foo_bar2` add index `foo_bar2_baz_id_index`(`baz_id`); @@ -69,18 +46,11 @@ alter table `foo_bar2` add unique `foo_bar2_baz_id_unique`(`baz_id`); alter table `foo_bar2` add index `foo_bar2_foo_bar_id_index`(`foo_bar_id`); alter table `foo_bar2` add unique `foo_bar2_foo_bar_id_unique`(`foo_bar_id`); -create table `foo_baz2` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `version` datetime(3) not null default current_timestamp(3)) default character set utf8mb4 engine = InnoDB; - create table `foo_param2` (`bar_id` int(11) unsigned not null, `baz_id` int(11) unsigned not null, `value` varchar(255) not null) default character set utf8mb4 engine = InnoDB; alter table `foo_param2` add index `foo_param2_bar_id_index`(`bar_id`); alter table `foo_param2` add index `foo_param2_baz_id_index`(`baz_id`); alter table `foo_param2` add primary key `foo_param2_pkey`(`bar_id`, `baz_id`); -create table `configuration2` (`property` varchar(255) not null, `test_id` int(11) unsigned not null, `value` varchar(255) not null) default character set utf8mb4 engine = InnoDB; -alter table `configuration2` add index `configuration2_property_index`(`property`); -alter table `configuration2` add index `configuration2_test_id_index`(`test_id`); -alter table `configuration2` add primary key `configuration2_pkey`(`property`, `test_id`); - create table `dummy2` (`id` int unsigned not null auto_increment primary key) default character set utf8mb4 engine = InnoDB; create table `car2` (`name` varchar(100) not null, `year` int(11) unsigned not null, `price` int(11) not null) default character set utf8mb4 engine = InnoDB; @@ -92,28 +62,59 @@ create table `car_owner2` (`id` int unsigned not null auto_increment primary key alter table `car_owner2` add index `car_owner2_car_name_car_year_index`(`car_name`, `car_year`); create table `user2` (`first_name` varchar(100) not null, `last_name` varchar(100) not null, `foo` int(11) null, `favourite_car_name` varchar(100) null, `favourite_car_year` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; -alter table `user2` add index `user2_first_name_index`(`first_name`); -alter table `user2` add index `user2_last_name_index`(`last_name`); alter table `user2` add unique `user2_favourite_car_name_unique`(`favourite_car_name`); alter table `user2` add unique `user2_favourite_car_year_unique`(`favourite_car_year`); alter table `user2` add primary key `user2_pkey`(`first_name`, `last_name`); alter table `user2` add index `user2_favourite_car_name_favourite_car_year_index`(`favourite_car_name`, `favourite_car_year`); -create table `base_user2` (`id` int unsigned not null auto_increment primary key, `first_name` varchar(100) not null, `last_name` varchar(100) not null, `type` enum('employee', 'manager', 'owner') not null, `employee_prop` int(11) null, `manager_prop` varchar(255) null, `owner_prop` varchar(255) null, `favourite_employee_id` int(11) unsigned null, `favourite_manager_id` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; +create table `user2_sandwiches` (`user2_first_name` varchar(100) not null, `user2_last_name` varchar(100) not null, `sandwich_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table `user2_sandwiches` add index `user2_sandwiches_sandwich_id_index`(`sandwich_id`); +alter table `user2_sandwiches` add primary key `user2_sandwiches_pkey`(`user2_first_name`, `user2_last_name`, `sandwich_id`); +alter table `user2_sandwiches` add index `user2_sandwiches_user2_first_name_user2_last_name_index`(`user2_first_name`, `user2_last_name`); + +create table `user2_cars` (`user2_first_name` varchar(100) not null, `user2_last_name` varchar(100) not null, `car2_name` varchar(100) not null, `car2_year` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table `user2_cars` add primary key `user2_cars_pkey`(`user2_first_name`, `user2_last_name`, `car2_name`, `car2_year`); +alter table `user2_cars` add index `user2_cars_user2_first_name_user2_last_name_index`(`user2_first_name`, `user2_last_name`); +alter table `user2_cars` add index `user2_cars_car2_name_car2_year_index`(`car2_name`, `car2_year`); + +create table `book_tag2` (`id` bigint unsigned not null auto_increment primary key, `name` varchar(50) not null) default character set utf8mb4 engine = InnoDB; + +create table `base_user2` (`id` int unsigned not null auto_increment primary key, `first_name` varchar(100) not null, `last_name` varchar(100) not null, `type` enum('employee', 'manager', 'owner') not null, `owner_prop` varchar(255) null, `favourite_employee_id` int(11) unsigned null, `favourite_manager_id` int(11) unsigned null, `employee_prop` int(11) null, `manager_prop` varchar(255) null) default character set utf8mb4 engine = InnoDB; alter table `base_user2` add index `base_user2_type_index`(`type`); alter table `base_user2` add index `base_user2_favourite_employee_id_index`(`favourite_employee_id`); alter table `base_user2` add index `base_user2_favourite_manager_id_index`(`favourite_manager_id`); alter table `base_user2` add unique `base_user2_favourite_manager_id_unique`(`favourite_manager_id`); -create table `author_to_friend` (`author2_1_id` int(11) unsigned not null, `author2_2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; -alter table `author_to_friend` add index `author_to_friend_author2_1_id_index`(`author2_1_id`); -alter table `author_to_friend` add index `author_to_friend_author2_2_id_index`(`author2_2_id`); -alter table `author_to_friend` add primary key `author_to_friend_pkey`(`author2_1_id`, `author2_2_id`); +create table `author2` (`id` int unsigned not null auto_increment primary key, `created_at` datetime(3) not null default current_timestamp(3), `updated_at` datetime(3) not null default current_timestamp(3), `name` varchar(255) not null, `email` varchar(255) not null, `age` int(11) null default null, `terms_accepted` tinyint(1) not null default false, `optional` tinyint(1) null, `identities` text null, `born` date null, `born_time` time null, `favourite_book_uuid_pk` varchar(36) null, `favourite_author_id` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; +alter table `author2` add index `custom_email_index_name`(`email`); +alter table `author2` add unique `custom_email_unique_name`(`email`); +alter table `author2` add index `author2_terms_accepted_index`(`terms_accepted`); +alter table `author2` add index `author2_born_index`(`born`); +alter table `author2` add index `born_time_idx`(`born_time`); +alter table `author2` add index `author2_favourite_book_uuid_pk_index`(`favourite_book_uuid_pk`); +alter table `author2` add index `author2_favourite_author_id_index`(`favourite_author_id`); +alter table `author2` add index `custom_idx_name_123`(`name`); +alter table `author2` add index `author2_name_age_index`(`name`, `age`); +alter table `author2` add unique `author2_name_email_unique`(`name`, `email`); -create table `author2_following` (`author2_1_id` int(11) unsigned not null, `author2_2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; -alter table `author2_following` add index `author2_following_author2_1_id_index`(`author2_1_id`); -alter table `author2_following` add index `author2_following_author2_2_id_index`(`author2_2_id`); -alter table `author2_following` add primary key `author2_following_pkey`(`author2_1_id`, `author2_2_id`); +create table `book2` (`uuid_pk` varchar(36) not null, `created_at` datetime(3) not null default current_timestamp(3), `title` varchar(255) null default '', `perex` text null, `price` float null, `double` double null, `meta` json null, `author_id` int(11) unsigned not null, `publisher_id` int(11) unsigned null, `foo` varchar(255) null default 'lol') default character set utf8mb4 engine = InnoDB; +alter table `book2` add primary key `book2_pkey`(`uuid_pk`); +alter table `book2` add index `book2_author_id_index`(`author_id`); +alter table `book2` add index `book2_publisher_id_index`(`publisher_id`); + +create table `test2` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) null, `book_uuid_pk` varchar(36) null, `version` int(11) not null default 1, `foo___bar` int(11) unsigned null, `foo___baz` int(11) unsigned null) default character set utf8mb4 engine = InnoDB; +alter table `test2` add index `test2_book_uuid_pk_index`(`book_uuid_pk`); +alter table `test2` add unique `test2_book_uuid_pk_unique`(`book_uuid_pk`); +alter table `test2` add index `test2_foo___bar_index`(`foo___bar`); +alter table `test2` add unique `test2_foo___bar_unique`(`foo___bar`); + +create table `configuration2` (`property` varchar(255) not null, `test_id` int(11) unsigned not null, `value` varchar(255) not null) default character set utf8mb4 engine = InnoDB; +alter table `configuration2` add index `configuration2_test_id_index`(`test_id`); +alter table `configuration2` add primary key `configuration2_pkey`(`property`, `test_id`); + +create table `publisher2_tests` (`id` int unsigned not null auto_increment primary key, `publisher2_id` int(11) unsigned not null, `test2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table `publisher2_tests` add index `publisher2_tests_publisher2_id_index`(`publisher2_id`); +alter table `publisher2_tests` add index `publisher2_tests_test2_id_index`(`test2_id`); create table `book2_tags` (`order` int unsigned not null auto_increment primary key, `book2_uuid_pk` varchar(36) not null, `book_tag2_id` bigint unsigned not null) default character set utf8mb4 engine = InnoDB; alter table `book2_tags` add index `book2_tags_book2_uuid_pk_index`(`book2_uuid_pk`); @@ -124,25 +125,20 @@ alter table `book_to_tag_unordered` add index `book_to_tag_unordered_book2_uuid_ alter table `book_to_tag_unordered` add index `book_to_tag_unordered_book_tag2_id_index`(`book_tag2_id`); alter table `book_to_tag_unordered` add primary key `book_to_tag_unordered_pkey`(`book2_uuid_pk`, `book_tag2_id`); -create table `publisher2_tests` (`id` int unsigned not null auto_increment primary key, `publisher2_id` int(11) unsigned not null, `test2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; -alter table `publisher2_tests` add index `publisher2_tests_publisher2_id_index`(`publisher2_id`); -alter table `publisher2_tests` add index `publisher2_tests_test2_id_index`(`test2_id`); - -create table `user2_cars` (`user2_first_name` varchar(100) not null, `user2_last_name` varchar(100) not null, `car2_name` varchar(100) not null, `car2_year` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; -alter table `user2_cars` add primary key `user2_cars_pkey`(`user2_first_name`, `user2_last_name`, `car2_name`, `car2_year`); -alter table `user2_cars` add index `user2_cars_user2_first_name_user2_last_name_index`(`user2_first_name`, `user2_last_name`); -alter table `user2_cars` add index `user2_cars_car2_name_car2_year_index`(`car2_name`, `car2_year`); - -alter table `author2` add constraint `author2_favourite_book_uuid_pk_foreign` foreign key (`favourite_book_uuid_pk`) references `book2` (`uuid_pk`) on update no action on delete cascade; -alter table `author2` add constraint `author2_favourite_author_id_foreign` foreign key (`favourite_author_id`) references `author2` (`id`) on update cascade on delete set null; - -alter table `address2` add constraint `address2_author_id_foreign` foreign key (`author_id`) references `author2` (`id`) on update cascade on delete cascade; +create table `author_to_friend` (`author2_1_id` int(11) unsigned not null, `author2_2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table `author_to_friend` add index `author_to_friend_author2_1_id_index`(`author2_1_id`); +alter table `author_to_friend` add index `author_to_friend_author2_2_id_index`(`author2_2_id`); +alter table `author_to_friend` add primary key `author_to_friend_pkey`(`author2_1_id`, `author2_2_id`); -alter table `book2` add constraint `book2_author_id_foreign` foreign key (`author_id`) references `author2` (`id`); -alter table `book2` add constraint `book2_publisher_id_foreign` foreign key (`publisher_id`) references `publisher2` (`id`) on update cascade on delete cascade; +create table `author2_following` (`author2_1_id` int(11) unsigned not null, `author2_2_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; +alter table `author2_following` add index `author2_following_author2_1_id_index`(`author2_1_id`); +alter table `author2_following` add index `author2_following_author2_2_id_index`(`author2_2_id`); +alter table `author2_following` add primary key `author2_following_pkey`(`author2_1_id`, `author2_2_id`); -alter table `test2` add constraint `test2_book_uuid_pk_foreign` foreign key (`book_uuid_pk`) references `book2` (`uuid_pk`) on delete set null; -alter table `test2` add constraint `test2_foo___bar_foreign` foreign key (`foo___bar`) references `foo_bar2` (`id`) on update cascade on delete set null; +create table `address2` (`author_id` int(11) unsigned not null, `value` varchar(255) not null comment 'This is address property') default character set utf8mb4 engine = InnoDB comment = 'This is address table'; +alter table `address2` add primary key `address2_pkey`(`author_id`); +alter table `address2` add index `address2_author_id_index`(`author_id`); +alter table `address2` add unique `address2_author_id_unique`(`author_id`); alter table `foo_bar2` add constraint `foo_bar2_baz_id_foreign` foreign key (`baz_id`) references `foo_baz2` (`id`) on update cascade on delete set null; alter table `foo_bar2` add constraint `foo_bar2_foo_bar_id_foreign` foreign key (`foo_bar_id`) references `foo_bar2` (`id`) on update cascade on delete set null; @@ -150,46 +146,45 @@ alter table `foo_bar2` add constraint `foo_bar2_foo_bar_id_foreign` foreign key alter table `foo_param2` add constraint `foo_param2_bar_id_foreign` foreign key (`bar_id`) references `foo_bar2` (`id`) on update cascade; alter table `foo_param2` add constraint `foo_param2_baz_id_foreign` foreign key (`baz_id`) references `foo_baz2` (`id`) on update cascade; -alter table `configuration2` add constraint `configuration2_test_id_foreign` foreign key (`test_id`) references `test2` (`id`) on update cascade; +alter table `car_owner2` add constraint `car_owner2_car_name_car_year_foreign` foreign key (`car_name`, `car_year`) references `car2` (`name`, `year`) on update cascade; -alter table `car_owner2` add constraint `car_owner2_car_name_foreign` foreign key (`car_name`) references `car2` (`name`) on update cascade; -alter table `car_owner2` add constraint `car_owner2_car_year_foreign` foreign key (`car_year`) references `car2` (`year`) on update cascade; +alter table `user2` add constraint `user2_favourite_car_name_favourite_car_year_foreign` foreign key (`favourite_car_name`, `favourite_car_year`) references `car2` (`name`, `year`) on update cascade on delete set null; -alter table `user2` add constraint `user2_favourite_car_name_foreign` foreign key (`favourite_car_name`) references `car2` (`name`) on update cascade on delete set null; -alter table `user2` add constraint `user2_favourite_car_year_foreign` foreign key (`favourite_car_year`) references `car2` (`year`) on update cascade on delete set null; +alter table `user2_sandwiches` add constraint `user2_sandwiches_user2_first_name_user2_last_name_foreign` foreign key (`user2_first_name`, `user2_last_name`) references `user2` (`first_name`, `last_name`) on update cascade on delete cascade; +alter table `user2_sandwiches` add constraint `user2_sandwiches_sandwich_id_foreign` foreign key (`sandwich_id`) references `sandwich` (`id`) on update cascade on delete cascade; + +alter table `user2_cars` add constraint `user2_cars_user2_first_name_user2_last_name_foreign` foreign key (`user2_first_name`, `user2_last_name`) references `user2` (`first_name`, `last_name`) on update cascade on delete cascade; +alter table `user2_cars` add constraint `user2_cars_car2_name_car2_year_foreign` foreign key (`car2_name`, `car2_year`) references `car2` (`name`, `year`) on update cascade on delete cascade; alter table `base_user2` add constraint `base_user2_favourite_employee_id_foreign` foreign key (`favourite_employee_id`) references `base_user2` (`id`) on update cascade on delete set null; alter table `base_user2` add constraint `base_user2_favourite_manager_id_foreign` foreign key (`favourite_manager_id`) references `base_user2` (`id`) on update cascade on delete set null; -alter table `author_to_friend` add constraint `author_to_friend_author2_1_id_foreign` foreign key (`author2_1_id`) references `author2` (`id`) on update cascade on delete cascade; -alter table `author_to_friend` add constraint `author_to_friend_author2_2_id_foreign` foreign key (`author2_2_id`) references `author2` (`id`) on update cascade on delete cascade; +alter table `author2` add constraint `author2_favourite_book_uuid_pk_foreign` foreign key (`favourite_book_uuid_pk`) references `book2` (`uuid_pk`) on update no action on delete cascade; +alter table `author2` add constraint `author2_favourite_author_id_foreign` foreign key (`favourite_author_id`) references `author2` (`id`) on update cascade on delete set null; -alter table `author2_following` add constraint `author2_following_author2_1_id_foreign` foreign key (`author2_1_id`) references `author2` (`id`) on update cascade on delete cascade; -alter table `author2_following` add constraint `author2_following_author2_2_id_foreign` foreign key (`author2_2_id`) references `author2` (`id`) on update cascade on delete cascade; +alter table `book2` add constraint `book2_author_id_foreign` foreign key (`author_id`) references `author2` (`id`); +alter table `book2` add constraint `book2_publisher_id_foreign` foreign key (`publisher_id`) references `publisher2` (`id`) on update cascade on delete cascade; -alter table `book2_tags` add constraint `book2_tags_book2_uuid_pk_foreign` foreign key (`book2_uuid_pk`) references `book2` (`uuid_pk`) on update cascade on delete cascade; -alter table `book2_tags` add constraint `book2_tags_book_tag2_id_foreign` foreign key (`book_tag2_id`) references `book_tag2` (`id`) on update cascade on delete cascade; +alter table `test2` add constraint `test2_book_uuid_pk_foreign` foreign key (`book_uuid_pk`) references `book2` (`uuid_pk`) on delete set null; +alter table `test2` add constraint `test2_foo___bar_foreign` foreign key (`foo___bar`) references `foo_bar2` (`id`) on update cascade on delete set null; -alter table `book_to_tag_unordered` add constraint `book_to_tag_unordered_book2_uuid_pk_foreign` foreign key (`book2_uuid_pk`) references `book2` (`uuid_pk`) on update cascade on delete cascade; -alter table `book_to_tag_unordered` add constraint `book_to_tag_unordered_book_tag2_id_foreign` foreign key (`book_tag2_id`) references `book_tag2` (`id`) on update cascade on delete cascade; +alter table `configuration2` add constraint `configuration2_test_id_foreign` foreign key (`test_id`) references `test2` (`id`) on update cascade; alter table `publisher2_tests` add constraint `publisher2_tests_publisher2_id_foreign` foreign key (`publisher2_id`) references `publisher2` (`id`) on update cascade on delete cascade; alter table `publisher2_tests` add constraint `publisher2_tests_test2_id_foreign` foreign key (`test2_id`) references `test2` (`id`) on update cascade on delete cascade; -alter table `user2_cars` add constraint `user2_cars_user2_first_name_foreign` foreign key (`user2_first_name`) references `user2` (`first_name`) on update cascade on delete cascade; -alter table `user2_cars` add constraint `user2_cars_user2_last_name_foreign` foreign key (`user2_last_name`) references `user2` (`last_name`) on update cascade on delete cascade; -alter table `user2_cars` add constraint `user2_cars_car2_name_foreign` foreign key (`car2_name`) references `car2` (`name`) on update cascade on delete cascade; -alter table `user2_cars` add constraint `user2_cars_car2_year_foreign` foreign key (`car2_year`) references `car2` (`year`) on update cascade on delete cascade; +alter table `book2_tags` add constraint `book2_tags_book2_uuid_pk_foreign` foreign key (`book2_uuid_pk`) references `book2` (`uuid_pk`) on update cascade on delete cascade; +alter table `book2_tags` add constraint `book2_tags_book_tag2_id_foreign` foreign key (`book_tag2_id`) references `book_tag2` (`id`) on update cascade on delete cascade; -create table `sandwich` (`id` int unsigned not null auto_increment primary key, `name` varchar(255) not null, `price` int(11) not null) default character set utf8mb4 engine = InnoDB; +alter table `book_to_tag_unordered` add constraint `book_to_tag_unordered_book2_uuid_pk_foreign` foreign key (`book2_uuid_pk`) references `book2` (`uuid_pk`) on update cascade on delete cascade; +alter table `book_to_tag_unordered` add constraint `book_to_tag_unordered_book_tag2_id_foreign` foreign key (`book_tag2_id`) references `book_tag2` (`id`) on update cascade on delete cascade; -create table `user2_sandwiches` (`user2_first_name` varchar(100) not null, `user2_last_name` varchar(100) not null, `sandwich_id` int(11) unsigned not null) default character set utf8mb4 engine = InnoDB; -alter table `user2_sandwiches` add index `user2_sandwiches_sandwich_id_index`(`sandwich_id`); -alter table `user2_sandwiches` add primary key `user2_sandwiches_pkey`(`user2_first_name`, `user2_last_name`, `sandwich_id`); -alter table `user2_sandwiches` add index `user2_sandwiches_user2_first_name_user2_last_name_index`(`user2_first_name`, `user2_last_name`); +alter table `author_to_friend` add constraint `author_to_friend_author2_1_id_foreign` foreign key (`author2_1_id`) references `author2` (`id`) on update cascade on delete cascade; +alter table `author_to_friend` add constraint `author_to_friend_author2_2_id_foreign` foreign key (`author2_2_id`) references `author2` (`id`) on update cascade on delete cascade; -alter table `user2_sandwiches` add constraint `user2_sandwiches_user2_first_name_foreign` foreign key (`user2_first_name`) references `user2` (`first_name`) on update cascade on delete cascade; -alter table `user2_sandwiches` add constraint `user2_sandwiches_user2_last_name_foreign` foreign key (`user2_last_name`) references `user2` (`last_name`) on update cascade on delete cascade; -alter table `user2_sandwiches` add constraint `user2_sandwiches_sandwich_id_foreign` foreign key (`sandwich_id`) references `sandwich` (`id`) on update cascade on delete cascade; +alter table `author2_following` add constraint `author2_following_author2_1_id_foreign` foreign key (`author2_1_id`) references `author2` (`id`) on update cascade on delete cascade; +alter table `author2_following` add constraint `author2_following_author2_2_id_foreign` foreign key (`author2_2_id`) references `author2` (`id`) on update cascade on delete cascade; + +alter table `address2` add constraint `address2_author_id_foreign` foreign key (`author_id`) references `author2` (`id`) on update cascade on delete cascade; set foreign_key_checks = 1; diff --git a/tests/postgre-schema.sql b/tests/postgre-schema.sql index bcc4bb67aadc..b6edaf1e360d 100644 --- a/tests/postgre-schema.sql +++ b/tests/postgre-schema.sql @@ -1,22 +1,21 @@ set names 'utf8'; set session_replication_role = 'replica'; -drop table if exists "author2" cascade; -drop table if exists "address2" cascade; +drop table if exists "author2_following" cascade; +drop table if exists "author_to_friend" cascade; +drop table if exists "book_to_tag_unordered" cascade; +drop table if exists "book2_tags" cascade; +drop table if exists "publisher2_tests" cascade; +drop table if exists "configuration2" cascade; +drop table if exists "test2" cascade; drop table if exists "book2" cascade; +drop table if exists "address2" cascade; +drop table if exists "author2" cascade; drop table if exists "book_tag2" cascade; drop table if exists "publisher2" cascade; -drop table if exists "test2" cascade; +drop table if exists "foo_param2" cascade; drop table if exists "foo_bar2" cascade; drop table if exists "foo_baz2" cascade; -drop table if exists "foo_param2" cascade; -drop table if exists "configuration2" cascade; -drop table if exists "author_to_friend" cascade; -drop table if exists "author2_following" cascade; -drop table if exists "book2_tags" cascade; -drop table if exists "book_to_tag_unordered" cascade; -drop table if exists "publisher2_tests" cascade; -drop table if exists "book_to_tag_unordered" cascade; drop table if exists "label2" cascade; drop table if exists "new_table" cascade; @@ -24,6 +23,22 @@ drop table if exists "author2_to_author2" cascade; drop table if exists "book2_to_book_tag2" cascade; drop table if exists "publisher2_to_test2" cascade; +create table "label2" ("uuid" uuid not null, "name" varchar(255) not null); +alter table "label2" add constraint "label2_pkey" primary key ("uuid"); + +create table "foo_baz2" ("id" serial primary key, "name" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3)); + +create table "foo_bar2" ("id" serial primary key, "name" varchar(255) not null, "baz_id" int4 null, "foo_bar_id" int4 null, "version" timestamptz(0) not null default current_timestamp(0), "blob" bytea null, "array" text[] null, "object" jsonb null); +alter table "foo_bar2" add constraint "foo_bar2_baz_id_unique" unique ("baz_id"); +alter table "foo_bar2" add constraint "foo_bar2_foo_bar_id_unique" unique ("foo_bar_id"); + +create table "foo_param2" ("bar_id" int4 not null, "baz_id" int4 not null, "value" varchar(255) not null); +alter table "foo_param2" add constraint "foo_param2_pkey" primary key ("bar_id", "baz_id"); + +create table "publisher2" ("id" serial primary key, "name" varchar(255) not null, "type" text check ("type" in ('local', 'global')) not null, "type2" text check ("type2" in ('LOCAL', 'GLOBAL')) not null, "enum1" int2 null, "enum2" int2 null, "enum3" int2 null, "enum4" text check ("enum4" in ('a', 'b', 'c')) null); + +create table "book_tag2" ("id" bigserial primary key, "name" varchar(50) not null); + create table "author2" ("id" serial primary key, "created_at" timestamptz(3) not null default current_timestamp(3), "updated_at" timestamptz(3) not null default current_timestamp(3), "name" varchar(255) not null, "email" varchar(255) not null, "age" int4 null default null, "terms_accepted" bool not null default false, "optional" bool null, "identities" text[] null, "born" date null, "born_time" time(0) null, "favourite_book_uuid_pk" varchar(36) null, "favourite_author_id" int4 null); create index "custom_email_index_name" on "author2" ("email"); alter table "author2" add constraint "custom_email_unique_name" unique ("email"); @@ -35,37 +50,26 @@ create index "author2_name_age_index" on "author2" ("name", "age"); alter table "author2" add constraint "author2_name_email_unique" unique ("name", "email"); create table "address2" ("author_id" int4 not null, "value" varchar(255) not null); +comment on table "address2" is 'This is address table'; +comment on column "address2"."value" is 'This is address property'; alter table "address2" add constraint "address2_pkey" primary key ("author_id"); alter table "address2" add constraint "address2_author_id_unique" unique ("author_id"); create table "book2" ("uuid_pk" varchar(36) not null, "created_at" timestamptz(3) not null default current_timestamp(3), "title" varchar(255) null default '', "perex" text null, "price" float null, "double" numeric null, "meta" jsonb null, "author_id" int4 not null, "publisher_id" int4 null, "foo" varchar(255) null default 'lol'); alter table "book2" add constraint "book2_pkey" primary key ("uuid_pk"); -create table "book_tag2" ("id" bigserial primary key, "name" varchar(50) not null); - -create table "publisher2" ("id" serial primary key, "name" varchar(255) not null, "type" text check ("type" in ('local', 'global')) not null, "type2" text check ("type2" in ('LOCAL', 'GLOBAL')) not null, "enum1" int2 null, "enum2" int2 null, "enum3" int2 null, "enum4" text check ("enum4" in ('a', 'b', 'c')) null); - create table "test2" ("id" serial primary key, "name" varchar(255) null, "book_uuid_pk" varchar(36) null, "version" int4 not null default 1, "path" polygon null); alter table "test2" add constraint "test2_book_uuid_pk_unique" unique ("book_uuid_pk"); -create table "foo_bar2" ("id" serial primary key, "name" varchar(255) not null, "baz_id" int4 null, "foo_bar_id" int4 null, "version" timestamptz(0) not null default current_timestamp(0), "blob" bytea null, "array" text[] null, "object" jsonb null); -alter table "foo_bar2" add constraint "foo_bar2_baz_id_unique" unique ("baz_id"); -alter table "foo_bar2" add constraint "foo_bar2_foo_bar_id_unique" unique ("foo_bar_id"); - -create table "foo_baz2" ("id" serial primary key, "name" varchar(255) not null, "version" timestamptz(3) not null default current_timestamp(3)); +create table "configuration2" ("property" varchar(255) not null, "test_id" int4 not null, "value" varchar(255) not null); +alter table "configuration2" add constraint "configuration2_pkey" primary key ("property", "test_id"); -create table "foo_param2" ("bar_id" int4 not null, "baz_id" int4 not null, "value" varchar(255) not null); -create index "foo_param2_bar_id_index" on "foo_param2" ("bar_id"); -create index "foo_param2_baz_id_index" on "foo_param2" ("baz_id"); -alter table "foo_param2" add constraint "foo_param2_pkey" primary key ("bar_id", "baz_id"); +create table "publisher2_tests" ("id" serial primary key, "publisher2_id" int4 not null, "test2_id" int4 not null); -create table "label2" ("uuid" uuid not null, "name" varchar(255) not null); -alter table "label2" add constraint "label2_pkey" primary key ("uuid"); +create table "book2_tags" ("order" serial primary key, "book2_uuid_pk" varchar(36) not null, "book_tag2_id" bigint not null); -create table "configuration2" ("property" varchar(255) not null, "test_id" int4 not null, "value" varchar(255) not null); -create index "configuration2_property_index" on "configuration2" ("property"); -create index "configuration2_test_id_index" on "configuration2" ("test_id"); -alter table "configuration2" add constraint "configuration2_pkey" primary key ("property", "test_id"); +create table "book_to_tag_unordered" ("book2_uuid_pk" varchar(36) not null, "book_tag2_id" bigint not null); +alter table "book_to_tag_unordered" add constraint "book_to_tag_unordered_pkey" primary key ("book2_uuid_pk", "book_tag2_id"); create table "author_to_friend" ("author2_1_id" int4 not null, "author2_2_id" int4 not null); alter table "author_to_friend" add constraint "author_to_friend_pkey" primary key ("author2_1_id", "author2_2_id"); @@ -73,12 +77,11 @@ alter table "author_to_friend" add constraint "author_to_friend_pkey" primary ke create table "author2_following" ("author2_1_id" int4 not null, "author2_2_id" int4 not null); alter table "author2_following" add constraint "author2_following_pkey" primary key ("author2_1_id", "author2_2_id"); -create table "book2_tags" ("order" serial primary key, "book2_uuid_pk" varchar(36) not null, "book_tag2_id" bigint not null); - -create table "book_to_tag_unordered" ("book2_uuid_pk" varchar(36) not null, "book_tag2_id" bigint not null); -alter table "book_to_tag_unordered" add constraint "book_to_tag_unordered_pkey" primary key ("book2_uuid_pk", "book_tag2_id"); +alter table "foo_bar2" add constraint "foo_bar2_baz_id_foreign" foreign key ("baz_id") references "foo_baz2" ("id") on update cascade on delete set null; +alter table "foo_bar2" add constraint "foo_bar2_foo_bar_id_foreign" foreign key ("foo_bar_id") references "foo_bar2" ("id") on update cascade on delete set null; -create table "publisher2_tests" ("id" serial primary key, "publisher2_id" int4 not null, "test2_id" int4 not null); +alter table "foo_param2" add constraint "foo_param2_bar_id_foreign" foreign key ("bar_id") references "foo_bar2" ("id") on update cascade; +alter table "foo_param2" add constraint "foo_param2_baz_id_foreign" foreign key ("baz_id") references "foo_baz2" ("id") on update cascade; alter table "author2" add constraint "author2_favourite_book_uuid_pk_foreign" foreign key ("favourite_book_uuid_pk") references "book2" ("uuid_pk") on update no action on delete cascade; alter table "author2" add constraint "author2_favourite_author_id_foreign" foreign key ("favourite_author_id") references "author2" ("id") on update cascade on delete set null; @@ -90,19 +93,10 @@ alter table "book2" add constraint "book2_publisher_id_foreign" foreign key ("pu alter table "test2" add constraint "test2_book_uuid_pk_foreign" foreign key ("book_uuid_pk") references "book2" ("uuid_pk") on delete set null; -alter table "foo_bar2" add constraint "foo_bar2_baz_id_foreign" foreign key ("baz_id") references "foo_baz2" ("id") on update cascade on delete set null; -alter table "foo_bar2" add constraint "foo_bar2_foo_bar_id_foreign" foreign key ("foo_bar_id") references "foo_bar2" ("id") on update cascade on delete set null; - -alter table "foo_param2" add constraint "foo_param2_bar_id_foreign" foreign key ("bar_id") references "foo_bar2" ("id") on update cascade; -alter table "foo_param2" add constraint "foo_param2_baz_id_foreign" foreign key ("baz_id") references "foo_baz2" ("id") on update cascade; - alter table "configuration2" add constraint "configuration2_test_id_foreign" foreign key ("test_id") references "test2" ("id") on update cascade; -alter table "author_to_friend" add constraint "author_to_friend_author2_1_id_foreign" foreign key ("author2_1_id") references "author2" ("id") on update cascade on delete cascade; -alter table "author_to_friend" add constraint "author_to_friend_author2_2_id_foreign" foreign key ("author2_2_id") references "author2" ("id") on update cascade on delete cascade; - -alter table "author2_following" add constraint "author2_following_author2_1_id_foreign" foreign key ("author2_1_id") references "author2" ("id") on update cascade on delete cascade; -alter table "author2_following" add constraint "author2_following_author2_2_id_foreign" foreign key ("author2_2_id") references "author2" ("id") on update cascade on delete cascade; +alter table "publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "publisher2" ("id") on update cascade on delete cascade; +alter table "publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "test2" ("id") on update cascade on delete cascade; alter table "book2_tags" add constraint "book2_tags_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "book2" ("uuid_pk") on update cascade on delete cascade; alter table "book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreign key ("book_tag2_id") references "book_tag2" ("id") on update cascade on delete cascade; @@ -110,7 +104,10 @@ alter table "book2_tags" add constraint "book2_tags_book_tag2_id_foreign" foreig alter table "book_to_tag_unordered" add constraint "book_to_tag_unordered_book2_uuid_pk_foreign" foreign key ("book2_uuid_pk") references "book2" ("uuid_pk") on update cascade on delete cascade; alter table "book_to_tag_unordered" add constraint "book_to_tag_unordered_book_tag2_id_foreign" foreign key ("book_tag2_id") references "book_tag2" ("id") on update cascade on delete cascade; -alter table "publisher2_tests" add constraint "publisher2_tests_publisher2_id_foreign" foreign key ("publisher2_id") references "publisher2" ("id") on update cascade on delete cascade; -alter table "publisher2_tests" add constraint "publisher2_tests_test2_id_foreign" foreign key ("test2_id") references "test2" ("id") on update cascade on delete cascade; +alter table "author_to_friend" add constraint "author_to_friend_author2_1_id_foreign" foreign key ("author2_1_id") references "author2" ("id") on update cascade on delete cascade; +alter table "author_to_friend" add constraint "author_to_friend_author2_2_id_foreign" foreign key ("author2_2_id") references "author2" ("id") on update cascade on delete cascade; + +alter table "author2_following" add constraint "author2_following_author2_1_id_foreign" foreign key ("author2_1_id") references "author2" ("id") on update cascade on delete cascade; +alter table "author2_following" add constraint "author2_following_author2_2_id_foreign" foreign key ("author2_2_id") references "author2" ("id") on update cascade on delete cascade; set session_replication_role = 'origin'; diff --git a/tests/sqlite-schema.sql b/tests/sqlite-schema.sql index cd9f4ab32144..f63f96b30f03 100644 --- a/tests/sqlite-schema.sql +++ b/tests/sqlite-schema.sql @@ -1,29 +1,40 @@ pragma foreign_keys = off; -drop table if exists `author3`; +drop table if exists `book3_tags`; drop table if exists `book3`; +drop table if exists `author3`; drop table if exists `book_tag3`; +drop table if exists `publisher3_tests`; drop table if exists `publisher3`; drop table if exists `test3`; -drop table if exists `book3_tags`; -drop table if exists `publisher3_tests`; + drop table if exists `book3_to_book_tag3`; drop table if exists `publisher3_to_test3`; -create table `author3` (`id` integer not null primary key autoincrement, `created_at` datetime null, `updated_at` datetime null, `name` varchar not null, `email` varchar not null, `age` integer null, `terms_accepted` integer not null default 0, `identities` varchar null, `born` date null, `born_time` time null); -create unique index `author3_email_unique` on `author3` (`email`); +create table `test3` (`id` integer not null primary key autoincrement, `name` varchar null, `version` integer not null default 1); -create table `book3` (`id` integer not null primary key autoincrement, `created_at` datetime null, `updated_at` datetime null, `title` varchar not null default '', `foo` varchar null default 'lol'); +create table `publisher3` (`id` integer not null primary key autoincrement, `name` varchar not null, `type` varchar not null); + +create table `publisher3_tests` (`id` integer not null primary key autoincrement); create table `book_tag3` (`id` integer not null primary key autoincrement, `name` varchar not null, `version` datetime not null default current_timestamp); -create table `publisher3` (`id` integer not null primary key autoincrement, `name` varchar not null, `type` varchar not null); +create table `author3` (`id` integer not null primary key autoincrement, `created_at` datetime null, `updated_at` datetime null, `name` varchar not null, `email` varchar not null, `age` integer null, `terms_accepted` integer not null default 0, `identities` text null, `born` date(3) null, `born_time` time(3) null); +create unique index `author3_email_unique` on `author3` (`email`); -create table `test3` (`id` integer not null primary key autoincrement, `name` varchar null, `version` integer not null default 1); +create table `book3` (`id` integer not null primary key autoincrement, `created_at` datetime null, `updated_at` datetime null, `title` varchar not null default ''); create table `book3_tags` (`id` integer not null primary key autoincrement); -create table `publisher3_tests` (`id` integer not null primary key autoincrement); +alter table `publisher3_tests` add column `publisher3_id` integer null references `publisher3` (`id`) on delete cascade on update cascade; +alter table `publisher3_tests` add column `test3_id` integer null references `test3` (`id`) on delete cascade on update cascade; +create index `publisher3_tests_publisher3_id_index` on `publisher3_tests` (`publisher3_id`); +create index `publisher3_tests_test3_id_index` on `publisher3_tests` (`test3_id`); + +alter table `book3_tags` add column `book3_id` integer null references `book3` (`id`) on delete cascade on update cascade; +alter table `book3_tags` add column `book_tag3_id` integer null references `book_tag3` (`id`) on delete cascade on update cascade; +create index `book3_tags_book3_id_index` on `book3_tags` (`book3_id`); +create index `book3_tags_book_tag3_id_index` on `book3_tags` (`book_tag3_id`); alter table `author3` add column `favourite_book_id` integer null references `book3` (`id`) on delete set null on update cascade; create index `author3_favourite_book_id_index` on `author3` (`favourite_book_id`); @@ -33,14 +44,4 @@ alter table `book3` add column `publisher_id` integer null references `publisher create index `book3_author_id_index` on `book3` (`author_id`); create index `book3_publisher_id_index` on `book3` (`publisher_id`); -alter table `book3_tags` add column `book3_id` integer null references `book3` (`id`) on delete cascade on update cascade; -alter table `book3_tags` add column `book_tag3_id` integer null references `book_tag3` (`id`) on delete cascade on update cascade; -create index `book3_tags_book3_id_index` on `book3_tags` (`book3_id`); -create index `book3_tags_book_tag3_id_index` on `book3_tags` (`book_tag3_id`); - -alter table `publisher3_tests` add column `publisher3_id` integer null references `publisher3` (`id`) on delete cascade on update cascade; -alter table `publisher3_tests` add column `test3_id` integer null references `test3` (`id`) on delete cascade on update cascade; -create index `publisher3_tests_publisher3_id_index` on `publisher3_tests` (`publisher3_id`); -create index `publisher3_tests_test3_id_index` on `publisher3_tests` (`test3_id`); - pragma foreign_keys = on;