From 9ed409a8fa4e1f4eea6a69ee1bd7924e7026ab56 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Oct 2022 14:13:31 +0800 Subject: [PATCH 01/52] test: add tidb 6.3 docker --- .test_database_urls/tidb | 2 ++ Makefile | 6 ++++++ docker-compose.yml | 10 ++++++++++ query-engine/connector-test-kit-rs/test-configs/tidb | 4 ++++ 4 files changed, 22 insertions(+) create mode 100644 .test_database_urls/tidb create mode 100644 query-engine/connector-test-kit-rs/test-configs/tidb diff --git a/.test_database_urls/tidb b/.test_database_urls/tidb new file mode 100644 index 000000000000..03202cdf504c --- /dev/null +++ b/.test_database_urls/tidb @@ -0,0 +1,2 @@ +export TEST_DATABASE_URL="mysql://root@localhost:4000" +unset TEST_SHADOW_DATABASE_URL diff --git a/Makefile b/Makefile index 5ccd5a7068d0..21cce749cdc4 100644 --- a/Makefile +++ b/Makefile @@ -133,6 +133,12 @@ start-mysql_mariadb: dev-mariadb: start-mysql_mariadb cp $(CONFIG_PATH)/mariadb $(CONFIG_FILE) +start-tidb: + docker-compose -f docker-compose.yml up -d --remove-orphans tidb + +dev-tidb: start-tidb + cp $(CONFIG_PATH)/tidb $(CONFIG_FILE) + start-mssql_2019: docker-compose -f docker-compose.yml up -d --remove-orphans mssql-2019 diff --git a/docker-compose.yml b/docker-compose.yml index a1b655e79b41..f3caba0de86e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -171,6 +171,16 @@ services: - databases tmpfs: /var/lib/mariadb + tidb: + image: pingcap/tidb:6.3 + restart: always + platform: linux/x86_64 + ports: + - "4000:4000" + networks: + - databases + tmpfs: /var/lib/tidb + vitess-test-5_7: image: vitess/vttestserver:mysql57@sha256:2b132a22d08b3b227d9391f8f58ed7ab5c081ca07bf0f87a0c166729124d360a restart: always diff --git a/query-engine/connector-test-kit-rs/test-configs/tidb b/query-engine/connector-test-kit-rs/test-configs/tidb new file mode 100644 index 000000000000..e28e29c55318 --- /dev/null +++ b/query-engine/connector-test-kit-rs/test-configs/tidb @@ -0,0 +1,4 @@ +{ + "connector": "tidb", + "runner": "direct" +} \ No newline at end of file From 2c04cd042f40d7bc65dc40b5268d8892da8be577 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Oct 2022 14:14:41 +0800 Subject: [PATCH 02/52] test: add test setup for tidb --- libs/test-setup/src/mysql.rs | 4 + libs/test-setup/src/tags.rs | 1 + .../src/connector_tag/mod.rs | 9 ++ .../src/connector_tag/tidb.rs | 100 ++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs diff --git a/libs/test-setup/src/mysql.rs b/libs/test-setup/src/mysql.rs index 92a7dab94240..fe6eba8d56a0 100644 --- a/libs/test-setup/src/mysql.rs +++ b/libs/test-setup/src/mysql.rs @@ -48,6 +48,10 @@ pub(crate) fn get_mysql_tags(database_url: &str) -> Result, Strin if version.contains("MariaDB") { tags |= Tags::Mariadb } else { + if version.contains("TiDB") { + tags |= Tags::TiDB + } + if version.contains("vitess") { tags |= Tags::Vitess; } diff --git a/libs/test-setup/src/tags.rs b/libs/test-setup/src/tags.rs index 0550c63c1c4e..3933e99fa612 100644 --- a/libs/test-setup/src/tags.rs +++ b/libs/test-setup/src/tags.rs @@ -38,6 +38,7 @@ tags![ Postgres15 = 1 << 16, Postgres11 = 1 << 17, Postgres13 = 1 << 18, + TiDB = 1 << 19, ]; pub fn tags_from_comma_separated_list(input: &str) -> BitFlags { diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs index 26403250a23e..28fbec3a4f12 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs @@ -5,6 +5,7 @@ mod postgres; mod sql_server; mod sqlite; mod vitess; +mod tidb; pub use mongodb::*; pub use mysql::*; @@ -12,6 +13,7 @@ pub use postgres::*; pub use sql_server::*; pub use sqlite::*; pub use vitess::*; +pub use tidb::*; use crate::{datamodel_rendering::DatamodelRenderer, TestConfig, TestError}; use cockroachdb::*; @@ -73,6 +75,7 @@ pub enum ConnectorTag { MongoDb(MongoDbConnectorTag), Sqlite(SqliteConnectorTag), Vitess(VitessConnectorTag), + TiDB(TiDBConnectorTag), Cockroach(CockroachDbConnectorTag), } @@ -85,6 +88,7 @@ pub enum ConnectorVersion { Sqlite, CockroachDb, Vitess(Option), + TiDB, } impl From<&ConnectorTag> for ConnectorVersion { @@ -97,6 +101,7 @@ impl From<&ConnectorTag> for ConnectorVersion { ConnectorTag::Sqlite(_) => ConnectorVersion::Sqlite, ConnectorTag::Cockroach(_) => ConnectorVersion::CockroachDb, ConnectorTag::Vitess(c) => ConnectorVersion::Vitess(c.version()), + ConnectorTag::TiDB(_) => ConnectorVersion::TiDB, } } } @@ -111,6 +116,7 @@ impl fmt::Display for ConnectorTag { Self::Sqlite(_) => "SQLite", Self::Vitess(_) => "Vitess", Self::Cockroach(_) => "CockroachDB", + Self::TiDB(_) => "TiDB", }; write!(f, "{}", printable) @@ -142,6 +148,7 @@ impl fmt::Display for ConnectorVersion { None => "Vitess (unknown)".to_string(), }, Self::CockroachDb => "CockroachDB".to_string(), + Self::TiDB => "TiDB".to_string(), }; write!(f, "{}", printable) @@ -159,6 +166,7 @@ impl ConnectorTag { .chain(MongoDbConnectorTag::all().into_iter().map(Self::MongoDb)) .chain(SqliteConnectorTag::all().into_iter().map(Self::Sqlite)) .chain(CockroachDbConnectorTag::all().into_iter().map(Self::Cockroach)) + .chain(TiDBConnectorTag::all().into_iter().map(Self::TiDB)) .collect() } @@ -210,6 +218,7 @@ impl TryFrom<(&str, Option<&str>)> for ConnectorTag { "sqlserver" => Self::SqlServer(SqlServerConnectorTag::new(version)?), "cockroachdb" => Self::Cockroach(CockroachDbConnectorTag::new()), "postgres" => Self::Postgres(PostgresConnectorTag::new(version)?), + "tidb" => Self::TiDB(TiDBConnectorTag::new()), "mysql" => Self::MySql(MySqlConnectorTag::new(version)?), "mongodb" => Self::MongoDb(MongoDbConnectorTag::new(version)?), "vitess" => Self::Vitess(VitessConnectorTag::new(version)?), diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs new file mode 100644 index 000000000000..6fcbd2a9757b --- /dev/null +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -0,0 +1,100 @@ +use super::*; +use crate::{SqlDatamodelRenderer}; + +const CAPABILITIES: &[ConnectorCapability] = &[ + ConnectorCapability::Enums, + ConnectorCapability::EnumArrayPush, + ConnectorCapability::Json, + ConnectorCapability::AutoIncrementAllowedOnNonId, + ConnectorCapability::RelationFieldsInArbitraryOrder, + ConnectorCapability::CreateMany, + ConnectorCapability::WritableAutoincField, + ConnectorCapability::CreateSkipDuplicates, + ConnectorCapability::UpdateableId, + ConnectorCapability::JsonFilteringJsonPath, + ConnectorCapability::JsonFilteringAlphanumeric, + ConnectorCapability::CreateManyWriteableAutoIncId, + ConnectorCapability::AutoIncrement, + ConnectorCapability::CompoundIds, + ConnectorCapability::AnyId, + ConnectorCapability::SqlQueryRaw, + // ConnectorCapability::NamedForeignKeys, + ConnectorCapability::AdvancedJsonNullability, + ConnectorCapability::IndexColumnLengthPrefixing, + // ConnectorCapability::FullTextIndex, + // ConnectorCapability::FullTextSearchWithIndex, + // ConnectorCapability::MultipleFullTextAttributesPerModel, + ConnectorCapability::ImplicitManyToManyRelation, + ConnectorCapability::DecimalType, + ConnectorCapability::OrderByNullsFirstLast, + ConnectorCapability::SupportsTxIsolationReadUncommitted, + ConnectorCapability::SupportsTxIsolationReadCommitted, + ConnectorCapability::SupportsTxIsolationRepeatableRead, + // ConnectorCapability::SupportsTxIsolationSerializable, +]; + +#[derive(Debug, Default, Clone, PartialEq)] +pub struct TiDBConnectorTag { + capabilities: Vec, +} + +impl ConnectorTagInterface for TiDBConnectorTag { + fn datamodel_provider(&self) -> &'static str { + "mysql" + } + + fn datamodel_renderer(&self) -> Box { + Box::new(SqlDatamodelRenderer::new()) + } + + fn connection_string( + &self, + database: &str, + is_ci: bool, + _is_multi_schema: bool, + _: Option<&'static str>, + ) -> String { + // Use the same database and schema name for CockroachDB - unfortunately CockroachDB + // can't handle 1 schema per test in a database well at this point in time. + if is_ci { + format!("mysql://root@localhost:4000/{}", database) + } else { + format!("mysql://root@localhost:4000/{}", database) + } + } + + + fn capabilities(&self) -> &[ConnectorCapability] { + &self.capabilities + } + + fn as_parse_pair(&self) -> (String, Option) { + ("tidb".to_owned(), None) + } + + fn is_versioned(&self) -> bool { + false + } + + fn relation_mode(&self) -> &'static str { + "prisma" + } + +} + +impl TiDBConnectorTag { + pub fn new() -> Self { + Self { + capabilities: tidb_capabilities(), + } + } + + /// Returns all versions of this connector. + pub fn all() -> Vec { + vec![Self::new()] + } +} + +fn tidb_capabilities() -> Vec { + (&CAPABILITIES).to_vec().to_owned() +} From 4dba8b9e96334e2bd646427c722be1fecf3b0706 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Oct 2022 14:15:07 +0800 Subject: [PATCH 03/52] test: add tidb into the migration engine tests --- .../src/multi_engine_test_api.rs | 5 +++ .../migration-engine-tests/src/test_api.rs | 5 +++ .../tests/apply_migrations/mod.rs | 2 ++ .../tests/existing_data/mod.rs | 2 +- .../tests/migrations/advisory_locking.rs | 4 +-- .../tests/migrations/foreign_keys.rs | 2 +- .../tests/migrations/id.rs | 18 +++++++---- .../tests/migrations/indexes.rs | 12 +++---- .../tests/migrations/mysql.rs | 31 ++++++++++++++++--- .../tests/migrations/relations.rs | 26 ++++++++-------- .../tests/migrations/reset_tests.rs | 2 +- .../tests/migrations/sql.rs | 6 ++-- .../tests/migrations/unsupported_types.rs | 2 ++ .../tests/native_types/mysql.rs | 6 ++-- 14 files changed, 82 insertions(+), 41 deletions(-) diff --git a/migration-engine/migration-engine-tests/src/multi_engine_test_api.rs b/migration-engine/migration-engine-tests/src/multi_engine_test_api.rs index 6b38fa7754b4..96085e503c9a 100644 --- a/migration-engine/migration-engine-tests/src/multi_engine_test_api.rs +++ b/migration-engine/migration-engine-tests/src/multi_engine_test_api.rs @@ -148,6 +148,11 @@ impl TestApi { self.tags().contains(Tags::CockroachDb) } + /// Returns true only when testing on tidb. + pub fn is_tidb(&self) -> bool { + self.tags().contains(Tags::TiDB) + } + /// Returns true only when testing on sqlite. pub fn is_sqlite(&self) -> bool { self.tags().contains(Tags::Sqlite) diff --git a/migration-engine/migration-engine-tests/src/test_api.rs b/migration-engine/migration-engine-tests/src/test_api.rs index 31e856caa1c4..c76fec1661fb 100644 --- a/migration-engine/migration-engine-tests/src/test_api.rs +++ b/migration-engine/migration-engine-tests/src/test_api.rs @@ -171,6 +171,11 @@ impl TestApi { self.root.is_cockroach() } + /// Returns true only when testing on tidb. + pub fn is_tidb(&self) -> bool { + self.root.is_tidb() + } + /// Returns true only when testing on sqlite. pub fn is_sqlite(&self) -> bool { self.root.is_sqlite() diff --git a/migration-engine/migration-engine-tests/tests/apply_migrations/mod.rs b/migration-engine/migration-engine-tests/tests/apply_migrations/mod.rs index 466cd7dcde6d..d0a414c5c8a9 100644 --- a/migration-engine/migration-engine-tests/tests/apply_migrations/mod.rs +++ b/migration-engine/migration-engine-tests/tests/apply_migrations/mod.rs @@ -126,6 +126,7 @@ fn migrations_should_fail_when_the_script_is_invalid(api: TestApi) { error_code = match api.tags() { t if t.contains(Tags::Vitess) => 1105, t if t.contains(Tags::Mysql) => 1064, + t if t.contains(Tags::TiDB) => 1064, t if t.contains(Tags::Mssql) => 102, t if t.contains(Tags::Postgres) => 42601, t if t.contains(Tags::Sqlite) => 1, @@ -139,6 +140,7 @@ fn migrations_should_fail_when_the_script_is_invalid(api: TestApi) { ^ HINT: try \h SELECT "#}, + t if t.contains(Tags::TiDB) => "You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 10 column 10 near \"^.^)_n;\n\" ", t if t.contains(Tags::Vitess) => "syntax error at position 10", t if t.contains(Tags::Mariadb) => "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'^.^)_n\' at line 1", t if t.contains(Tags::Mysql) => "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'^.^)_n\' at line 1", diff --git a/migration-engine/migration-engine-tests/tests/existing_data/mod.rs b/migration-engine/migration-engine-tests/tests/existing_data/mod.rs index 82ac9d2b4b5f..21de2dff83bf 100644 --- a/migration-engine/migration-engine-tests/tests/existing_data/mod.rs +++ b/migration-engine/migration-engine-tests/tests/existing_data/mod.rs @@ -779,7 +779,7 @@ fn set_default_current_timestamp_on_existing_column_works(api: TestApi) { } // exclude: there is a cockroach-specific test. It's unexecutable there. -#[test_connector(preview_features("referentialIntegrity"), exclude(CockroachDb))] +#[test_connector(preview_features("referentialIntegrity"), exclude(CockroachDb, TiDB))] fn primary_key_migrations_do_not_cause_data_loss(api: TestApi) { let dm1 = r#" model Dog { diff --git a/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs b/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs index 20f0bf92deed..08ab4c1245c0 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs @@ -33,7 +33,7 @@ fn advisory_locking_works(mut api: TestApi) { // We move the engines into the async block so they get dropped when they // are done with the request, releasing the lock as a consequence. async move { - second_me + first_me .apply_migrations(&migrations_directory) .send() .await @@ -41,7 +41,7 @@ fn advisory_locking_works(mut api: TestApi) { .into_output() }, async move { - first_me + second_me .apply_migrations(&migrations_directory_2) .send() .await diff --git a/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs b/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs index 6bce9d7f0d35..0f3425415095 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs @@ -284,7 +284,7 @@ fn changing_a_foreign_key_constrained_column_from_nullable_to_required_and_back_ api.schema_push_w_datasource(dm).send().assert_green(); } -#[test_connector(exclude(CockroachDb), preview_features("referentialIntegrity"))] +#[test_connector(exclude(CockroachDb, TiDB), preview_features("referentialIntegrity"))] fn changing_all_referenced_columns_of_foreign_key_works(api: TestApi) { let dm1 = r#" model Post { diff --git a/migration-engine/migration-engine-tests/tests/migrations/id.rs b/migration-engine/migration-engine-tests/tests/migrations/id.rs index 5e0cba6332ed..2ca3db12e58a 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/id.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/id.rs @@ -107,8 +107,9 @@ fn length_prefixed_compound_primary_key(api: TestApi) { }); } +// Ignoring TiDB, unsupported drop primary key when the table's pkIsHandle is true. // TODO: ignore because not possible on cockroachdb. We would need a multi-step process there. -#[test_connector(exclude(Vitess), exclude(CockroachDb))] +#[test_connector(exclude(Vitess), exclude(CockroachDb, TiDB))] fn changing_the_type_of_an_id_field_must_work(api: TestApi) { let dm1 = r#" model A { @@ -184,7 +185,8 @@ fn models_with_an_autoincrement_field_as_part_of_a_multi_field_id_can_be_created } // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. -#[test_connector(exclude(Sqlite, CockroachDb))] +// Ignoring TiDB, we can't set auto_increment for an existing id field to auto-incrementing in TiDB. +#[test_connector(exclude(Sqlite, CockroachDb, TiDB))] fn making_an_existing_id_field_autoincrement_works(api: TestApi) { use quaint::ast::{Insert, Select}; @@ -257,8 +259,9 @@ fn making_an_existing_id_field_autoincrement_works(api: TestApi) { } // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. +// Ignoring TiDB, we can't remove auto_increment without @@tidb_allow_remove_auto_inc enabled. // We test this separately on cockroachdb. -#[test_connector(exclude(Sqlite, CockroachDb))] +#[test_connector(exclude(Sqlite, CockroachDb, TiDB))] fn removing_autoincrement_from_an_existing_field_works(api: TestApi) { use quaint::ast::{Insert, Select}; @@ -390,7 +393,8 @@ fn making_an_existing_id_field_autoincrement_works_with_indices(api: TestApi) { // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. // Cockroachdb is tested separately. -#[test_connector(exclude(Sqlite, CockroachDb))] +// For TiDB case, we can't remove auto_increment without @@tidb_allow_remove_auto_inc enabled. +#[test_connector(exclude(Sqlite, CockroachDb, TiDB))] fn flipping_autoincrement_on_and_off_works(api: TestApi) { let dm_without = r#" model Post { @@ -413,7 +417,8 @@ fn flipping_autoincrement_on_and_off_works(api: TestApi) { // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. // Ignoring cockroachdb, because literal defaults on PKs on cockroachdb do not work. -#[test_connector(exclude(Sqlite, CockroachDb))] +// Ignoring TiDB, because we can't remove auto_increment without @@tidb_allow_remove_auto_inc enabled. +#[test_connector(exclude(Sqlite, CockroachDb, TiDB))] fn making_an_autoincrement_default_an_expression_then_autoincrement_again_works(api: TestApi) { let dm1 = r#" model Post { @@ -460,7 +465,8 @@ fn making_an_autoincrement_default_an_expression_then_autoincrement_again_works( }); } -#[test_connector(exclude(CockroachDb))] +// Ignoring TiDB, we can't drop column id with composite index covered or Primary Key covered now. +#[test_connector(exclude(CockroachDb, TiDB))] fn migrating_a_unique_constraint_to_a_primary_key_works(api: TestApi) { let dm = r#" model model1 { diff --git a/migration-engine/migration-engine-tests/tests/migrations/indexes.rs b/migration-engine/migration-engine-tests/tests/migrations/indexes.rs index 03f9bd7e4995..018e1a62aa76 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/indexes.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/indexes.rs @@ -108,7 +108,7 @@ fn unique_directive_on_required_one_to_one_relation_creates_one_index(api: TestA .assert_table("Cat", |table| table.assert_indexes_count(1)); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn one_to_many_self_relations_do_not_create_a_unique_index(api: TestApi) { let dm = r#" model Location { @@ -854,7 +854,7 @@ fn removal_index_length_prefix_should_not_happen_without_preview_feature(api: Te api.schema_push_w_datasource(dm).send().assert_no_steps(); } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), exclude(TiDB), preview_features("fullTextIndex"))] fn fulltext_index(api: TestApi) { let dm = formatdoc! {r#" {} @@ -880,7 +880,7 @@ fn fulltext_index(api: TestApi) { }); } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), exclude(TiDB), preview_features("fullTextIndex"))] fn fulltext_index_with_map(api: TestApi) { let dm = indoc! {r#" datasource db { @@ -909,7 +909,7 @@ fn fulltext_index_with_map(api: TestApi) { }); } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] fn do_not_overwrite_fulltext_index_without_preview_feature(api: TestApi) { let sql = indoc! {r#" CREATE TABLE `A` ( @@ -936,7 +936,7 @@ fn do_not_overwrite_fulltext_index_without_preview_feature(api: TestApi) { api.schema_push_w_datasource(dm).send().assert_no_steps(); } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), exclude(TiDB), preview_features("fullTextIndex"))] fn adding_fulltext_index_to_an_existing_column(api: TestApi) { let dm = indoc! {r#" model A { @@ -968,7 +968,7 @@ fn adding_fulltext_index_to_an_existing_column(api: TestApi) { }); } -#[test_connector(tags(Mysql), exclude(Mysql56), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), exclude(Mysql56, TiDB), preview_features("fullTextIndex"))] fn changing_normal_index_to_a_fulltext_index(api: TestApi) { let dm = indoc! {r#" model A { diff --git a/migration-engine/migration-engine-tests/tests/migrations/mysql.rs b/migration-engine/migration-engine-tests/tests/migrations/mysql.rs index f5dbae158727..38bd40c6d99e 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/mysql.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/mysql.rs @@ -6,7 +6,7 @@ use std::fmt::Write as _; // We need to test this specifically for mysql, because foreign keys are indexes, and they are // inferred as both foreign key and index by the sql-schema-describer. We do not want to // create/delete a second index. -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] fn indexes_on_foreign_key_fields_are_not_created_twice(api: TestApi) { let schema = r#" model Human { @@ -217,8 +217,18 @@ fn native_type_columns_can_be_created(api: TestApi) { ("decimal", "Decimal", "Decimal(5, 3)", "decimal(5,3)"), ("float", "Float", "Float", "float"), ("double", "Float", "Double", "double"), - ("bits", "Bytes", "Bit(10)", "bit(10)"), - ("bit", "Boolean", "Bit(1)", "bit(1)"), + ( + "bits", + "Bytes", + "Bit(10)", + if api.is_tidb() { "bit(10) unsigned" } else { "bit(10)" }, + ), + ( + "bit", + "Boolean", + "Bit(1)", + if api.is_tidb() { "bit(1) unsigned" } else { "bit(1)" }, + ), ("chars", "String", "Char(10)", "char(10)"), ("varchars", "String", "VarChar(500)", "varchar(500)"), ("binary", "Bytes", "Binary(230)", "binary(230)"), @@ -240,7 +250,18 @@ fn native_type_columns_can_be_created(api: TestApi) { "Timestamp(3)", "timestamp(3)", ), - ("year", "Int", "Year", if api.is_mysql_8() { "year" } else { "year(4)" }), + ( + "year", + "Int", + "Year", + if api.is_mysql_8() { + "year" + } else if api.is_tidb() { + "year(4) unsigned" + } else { + "year(4)" + } + ), ]; let mut dm = r#" @@ -491,7 +512,7 @@ fn dropping_m2m_relation_from_datamodel_works() { expected.assert_eq(&diff); } -#[cfg_attr(not(target_os = "windows"), test_connector(tags(Mysql), exclude(Vitess)))] +#[cfg_attr(not(target_os = "windows"), test_connector(tags(Mysql), exclude(Vitess, TiDB)))] fn alter_constraint_name(mut api: TestApi) { let plain_dm = api.datamodel_with_provider( r#" diff --git a/migration-engine/migration-engine-tests/tests/migrations/relations.rs b/migration-engine/migration-engine-tests/tests/migrations/relations.rs index 044ad64206e5..9fd5013f782c 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/relations.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/relations.rs @@ -111,7 +111,7 @@ fn adding_an_inline_relation_must_result_in_a_foreign_key_in_the_model_table(api }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn specifying_a_db_name_for_an_inline_relation_must_work(api: TestApi) { let dm1 = r#" model A { @@ -261,7 +261,7 @@ fn removing_an_inline_relation_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn compound_foreign_keys_should_work_in_correct_order(api: TestApi) { let dm1 = r#" model A { @@ -406,7 +406,7 @@ fn relations_can_reference_arbitrary_unique_fields_with_maps(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn relations_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -437,7 +437,7 @@ fn relations_can_reference_multiple_fields(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn a_relation_with_mappings_on_both_sides_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -470,7 +470,7 @@ fn a_relation_with_mappings_on_both_sides_can_reference_multiple_fields(api: Tes }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn relations_with_mappings_on_referenced_side_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -502,7 +502,7 @@ fn relations_with_mappings_on_referenced_side_can_reference_multiple_fields(api: }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn relations_with_mappings_on_referencing_side_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -624,7 +624,7 @@ fn on_delete_restrict_should_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn on_update_referential_actions_should_work(api: TestApi) { let actions = &[ (ReferentialAction::NoAction, ForeignKeyAction::NoAction), @@ -787,7 +787,7 @@ fn on_delete_optional_default_action(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn on_delete_compound_optional_optional_default_action(api: TestApi) { let dm = r#" model A { @@ -817,7 +817,7 @@ fn on_delete_compound_optional_optional_default_action(api: TestApi) { }); } -#[test_connector(exclude(Mssql, Vitess))] +#[test_connector(exclude(Mssql, Vitess, TiDB))] fn on_delete_compound_required_optional_default_action_with_restrict(api: TestApi) { let dm = r#" model A { @@ -927,7 +927,7 @@ fn on_update_required_default_action(api: TestApi) { }); } -#[test_connector(exclude(Vitess, CockroachDb))] +#[test_connector(exclude(Vitess, CockroachDb, TiDB))] fn adding_mutual_references_on_existing_tables_works(api: TestApi) { let dm1 = r#" model A { @@ -1067,7 +1067,7 @@ fn removing_a_relation_field_must_work(api: TestApi) { .assert_table("User", |table| table.assert_does_not_have_column("address_name")); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn references_to_models_with_compound_primary_keys_must_work(api: TestApi) { let dm = r#" model User { @@ -1101,7 +1101,7 @@ fn references_to_models_with_compound_primary_keys_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn join_tables_between_models_with_compound_primary_keys_must_work(api: TestApi) { let dm = r#" model Human { @@ -1161,7 +1161,7 @@ fn join_tables_between_models_with_compound_primary_keys_must_work(api: TestApi) }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn join_tables_between_models_with_mapped_compound_primary_keys_must_work(api: TestApi) { let dm = r#" model Human { diff --git a/migration-engine/migration-engine-tests/tests/migrations/reset_tests.rs b/migration-engine/migration-engine-tests/tests/migrations/reset_tests.rs index df5d329b8f2a..99e2b788c558 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/reset_tests.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/reset_tests.rs @@ -58,7 +58,7 @@ fn reset_then_apply_with_migrations_directory_works(api: TestApi) { .assert_has_table("_prisma_migrations"); } -#[test_connector] +#[test_connector(exclude(TiDB))] fn reset_then_diagnostics_with_migrations_directory_works(api: TestApi) { let dm = api.datamodel_with_provider( r#" diff --git a/migration-engine/migration-engine-tests/tests/migrations/sql.rs b/migration-engine/migration-engine-tests/tests/migrations/sql.rs index 4baba1ffcd7b..f60b88834078 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/sql.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/sql.rs @@ -71,7 +71,7 @@ fn creating_tables_without_primary_key_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn relations_to_models_without_a_primary_key_work(api: TestApi) { let dm = r#" model Pair { @@ -282,7 +282,7 @@ fn id_as_part_of_relation_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn multi_field_id_as_part_of_relation_must_work(api: TestApi) { let dm = r##" model Cat { @@ -314,7 +314,7 @@ fn multi_field_id_as_part_of_relation_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess))] +#[test_connector(exclude(Vitess, TiDB))] fn remapped_multi_field_id_as_part_of_relation_must_work(api: TestApi) { let dm = r##" model Cat { diff --git a/migration-engine/migration-engine-tests/tests/migrations/unsupported_types.rs b/migration-engine/migration-engine-tests/tests/migrations/unsupported_types.rs index d93caa7163ef..51bae51cfaae 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/unsupported_types.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/unsupported_types.rs @@ -206,6 +206,8 @@ fn using_unsupported_and_ignore_should_work(api: TestApi) { "interval" } else if api.is_postgres() { "macaddr" + } else if api.is_tidb() { + "set('a', 'b')" } else if api.is_mysql() { "point" } else if api.is_mssql() { diff --git a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs index 064a3bfab3ca..6cbd036e64d2 100644 --- a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs +++ b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs @@ -740,7 +740,7 @@ fn filter_to_types(api: &TestApi, to_types: &'static [&'static str]) -> Cow<'sta to_types.into() } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] fn safe_casts_with_existing_data_should_work(api: TestApi) { let connector = psl::builtin_connectors::MYSQL; let mut dm1 = String::with_capacity(256); @@ -785,7 +785,7 @@ fn safe_casts_with_existing_data_should_work(api: TestApi) { } } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] fn risky_casts_with_existing_data_should_warn(api: TestApi) { let connector = psl::builtin_connectors::MYSQL; let mut dm1 = String::with_capacity(256); @@ -847,7 +847,7 @@ fn risky_casts_with_existing_data_should_warn(api: TestApi) { } } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] fn impossible_casts_with_existing_data_should_warn(api: TestApi) { let connector = psl::builtin_connectors::MYSQL; let mut dm1 = String::with_capacity(256); From a4952f865d86a39801a69d8fe9ce96721d003937 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Oct 2022 14:15:29 +0800 Subject: [PATCH 04/52] test: add tidb into the introspection engine tests --- .../tests/identify_version/mod.rs | 2 +- .../tests/re_introspection/mysql.rs | 4 ++-- .../tests/referential_actions/mod.rs | 6 ++--- .../tests/relations/mysql.rs | 18 +++++++------- .../tests/relations_with_compound_fk/mysql.rs | 24 +++++++++---------- .../tests/remapping_database_names/mod.rs | 2 +- .../rpc_calls/get_metadata_command_tests.rs | 14 ++++++++++- .../tests/tables/mod.rs | 3 ++- .../tests/tables/mysql.rs | 10 ++++---- 9 files changed, 48 insertions(+), 35 deletions(-) diff --git a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs index 73aeeb2c7a4c..64605c245ea9 100644 --- a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs @@ -215,7 +215,7 @@ async fn introspect_postgres_prisma2(api: &TestApi) -> TestResult { //Mysql -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn introspect_mysql_non_prisma(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { diff --git a/introspection-engine/introspection-engine-tests/tests/re_introspection/mysql.rs b/introspection-engine/introspection-engine-tests/tests/re_introspection/mysql.rs index 041a4a96c495..21cd15ed0abe 100644 --- a/introspection-engine/introspection-engine-tests/tests/re_introspection/mysql.rs +++ b/introspection-engine/introspection-engine-tests/tests/re_introspection/mysql.rs @@ -41,7 +41,7 @@ async fn relation_mode_parameter_is_not_added(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn multiple_changed_relation_names(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -116,7 +116,7 @@ async fn multiple_changed_relation_names(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn mapped_model_and_field_name(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { diff --git a/introspection-engine/introspection-engine-tests/tests/referential_actions/mod.rs b/introspection-engine/introspection-engine-tests/tests/referential_actions/mod.rs index 352effb1b1db..17d2bcd84d9c 100644 --- a/introspection-engine/introspection-engine-tests/tests/referential_actions/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/referential_actions/mod.rs @@ -45,7 +45,7 @@ async fn referential_actions(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn referential_actions_mysql(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -156,7 +156,7 @@ async fn default_referential_actions_with_restrict_sqlite(api: &TestApi) -> Test Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn default_referential_actions_with_restrict_mysql(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -194,7 +194,7 @@ async fn default_referential_actions_with_restrict_mysql(api: &TestApi) -> TestR Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn default_optional_actions_mysql(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { diff --git a/introspection-engine/introspection-engine-tests/tests/relations/mysql.rs b/introspection-engine/introspection-engine-tests/tests/relations/mysql.rs index 58507af2731a..cd0ba59e20ab 100644 --- a/introspection-engine/introspection-engine-tests/tests/relations/mysql.rs +++ b/introspection-engine/introspection-engine-tests/tests/relations/mysql.rs @@ -5,7 +5,7 @@ use introspection_engine_tests::test_api::*; use quaint::prelude::Queryable; use test_macros::test_connector; -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn a_many_to_many_relation_with_an_id(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -60,7 +60,7 @@ async fn a_many_to_many_relation_with_an_id(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn a_one_req_to_many_relation(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -98,7 +98,7 @@ async fn a_one_req_to_many_relation(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn a_one_to_many_relation(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -136,7 +136,7 @@ async fn a_one_to_many_relation(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn a_self_relation(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -175,7 +175,7 @@ async fn a_self_relation(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn duplicate_fks_should_ignore_one_of_them(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -213,7 +213,7 @@ async fn duplicate_fks_should_ignore_one_of_them(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn one_to_many_relation_field_names_do_not_conflict_with_many_to_many_relation_field_names( api: &TestApi, ) -> TestResult { @@ -273,7 +273,7 @@ async fn one_to_many_relation_field_names_do_not_conflict_with_many_to_many_rela Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn relations_should_avoid_name_clashes(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -311,7 +311,7 @@ async fn relations_should_avoid_name_clashes(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn relations_should_avoid_name_clashes_2(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -642,7 +642,7 @@ async fn one_to_one_relation_on_a_singular_primary_key(api: &TestApi) -> TestRes Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn multiple_foreign_key_constraints_are_taken_always_in_the_same_order(api: &TestApi) -> TestResult { let migration = indoc! {r#" CREATE TABLE A ( diff --git a/introspection-engine/introspection-engine-tests/tests/relations_with_compound_fk/mysql.rs b/introspection-engine/introspection-engine-tests/tests/relations_with_compound_fk/mysql.rs index b95214b9c974..69e2e8f95850 100644 --- a/introspection-engine/introspection-engine-tests/tests/relations_with_compound_fk/mysql.rs +++ b/introspection-engine/introspection-engine-tests/tests/relations_with_compound_fk/mysql.rs @@ -3,7 +3,7 @@ use expect_test::expect; use introspection_engine_tests::test_api::*; use test_macros::test_connector; -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn a_compound_fk_pk_with_overlapping_primary_key(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -50,7 +50,7 @@ async fn a_compound_fk_pk_with_overlapping_primary_key(api: &TestApi) -> TestRes Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_duplicate_one_to_many_relations(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -107,7 +107,7 @@ async fn compound_foreign_keys_for_duplicate_one_to_many_relations(api: &TestApi Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_one_to_many_relations(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -154,7 +154,7 @@ async fn compound_foreign_keys_for_one_to_many_relations(api: &TestApi) -> TestR Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_one_to_many_relations_with_mixed_requiredness(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -201,7 +201,7 @@ async fn compound_foreign_keys_for_one_to_many_relations_with_mixed_requiredness Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_one_to_many_relations_with_non_unique_index(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -248,7 +248,7 @@ async fn compound_foreign_keys_for_one_to_many_relations_with_non_unique_index(a Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_one_to_one_relations(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -300,7 +300,7 @@ async fn compound_foreign_keys_for_one_to_one_relations(api: &TestApi) -> TestRe Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_required_one_to_one_relations(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -352,7 +352,7 @@ async fn compound_foreign_keys_for_required_one_to_one_relations(api: &TestApi) Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_required_one_to_many_relations(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -399,7 +399,7 @@ async fn compound_foreign_keys_for_required_one_to_many_relations(api: &TestApi) Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_required_self_relations(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -437,7 +437,7 @@ async fn compound_foreign_keys_for_required_self_relations(api: &TestApi) -> Tes Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_for_self_relations(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -475,7 +475,7 @@ async fn compound_foreign_keys_for_self_relations(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn compound_foreign_keys_with_defaults(api: &TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -513,7 +513,7 @@ async fn compound_foreign_keys_with_defaults(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn repro_matt_references_on_wrong_side(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { diff --git a/introspection-engine/introspection-engine-tests/tests/remapping_database_names/mod.rs b/introspection-engine/introspection-engine-tests/tests/remapping_database_names/mod.rs index 7cb424750fa9..bdce372ba60c 100644 --- a/introspection-engine/introspection-engine-tests/tests/remapping_database_names/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/remapping_database_names/mod.rs @@ -238,7 +238,7 @@ async fn remapping_models_in_relations_should_not_map_virtual_fields(api: &TestA Ok(()) } -#[test_connector(exclude(Sqlite, Mssql, Vitess, CockroachDb))] +#[test_connector(exclude(Sqlite, Mssql, Vitess, CockroachDb, TiDB))] async fn remapping_fields_in_compound_relations(api: &TestApi) -> TestResult { let sql_family = api.sql_family(); diff --git a/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs b/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs index aff04cf52660..b5e396c161c8 100644 --- a/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs +++ b/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs @@ -3,7 +3,7 @@ use introspection_engine_tests::{test_api::*, BarrelMigrationExecutor}; use pretty_assertions::assert_eq; use test_macros::test_connector; -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn metadata_for_mysql_should_work(api: &TestApi) -> TestResult { setup(&api.barrel(), api.db_name()).await?; @@ -15,6 +15,18 @@ async fn metadata_for_mysql_should_work(api: &TestApi) -> TestResult { Ok(()) } +#[test_connector(tags(TiDB))] +async fn metadata_for_tidb_should_work(api: &TestApi) -> TestResult { + setup(&api.barrel(), api.schema_name()).await?; + + let result = api.get_metadata().await?; + + assert_eq!(result.table_count, 3); + assert_eq!(result.size_in_bytes, 0); + + Ok(()) +} + #[test_connector(tags(Postgres), exclude(CockroachDb))] async fn metadata_for_postgres_should_work(api: &TestApi) -> TestResult { setup(&api.barrel(), api.schema_name()).await?; diff --git a/introspection-engine/introspection-engine-tests/tests/tables/mod.rs b/introspection-engine/introspection-engine-tests/tests/tables/mod.rs index 319e02deb98a..5d8fd5ef9fc2 100644 --- a/introspection-engine/introspection-engine-tests/tests/tables/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/tables/mod.rs @@ -708,7 +708,8 @@ async fn expression_indexes_should_be_ignored_on_sqlite(api: &TestApi) -> TestRe Ok(()) } -#[test_connector(tags(Mysql))] +// TiDB table names are case-insensitive by default, related pingcap/tidb#5714 +#[test_connector(tags(Mysql), exclude(TiDB))] async fn casing_should_not_lead_to_mix_ups(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { diff --git a/introspection-engine/introspection-engine-tests/tests/tables/mysql.rs b/introspection-engine/introspection-engine-tests/tests/tables/mysql.rs index be673a175e11..81241d4913a9 100644 --- a/introspection-engine/introspection-engine-tests/tests/tables/mysql.rs +++ b/introspection-engine/introspection-engine-tests/tests/tables/mysql.rs @@ -4,7 +4,7 @@ use introspection_engine_tests::test_api::*; use sql_introspection_connector::SqlIntrospectionConnector; use url::Url; -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn a_table_with_non_id_autoincrement(api: &TestApi) -> TestResult { let setup = r#" CREATE TABLE `Test` ( @@ -219,7 +219,7 @@ async fn a_table_with_descending_unique(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), preview_features("fullTextIndex"), exclude(TiDB))] async fn a_table_with_fulltext_index(api: &TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE `A` ( @@ -248,7 +248,7 @@ async fn a_table_with_fulltext_index(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), preview_features("fullTextIndex"), exclude(TiDB))] async fn a_table_with_fulltext_index_with_custom_name(api: &TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE `A` ( @@ -277,7 +277,7 @@ async fn a_table_with_fulltext_index_with_custom_name(api: &TestApi) -> TestResu Ok(()) } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn a_table_with_fulltext_index_without_preview_flag(api: &TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE `A` ( @@ -420,7 +420,7 @@ async fn missing_select_rights(api: &TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn northwind(api: TestApi) { let setup = include_str!("./northwind_mysql.sql"); api.raw_cmd(setup).await; From 17709f5b4ce50d65d08d86ab0d4d9b72f71a28ed Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Oct 2022 19:37:58 +0800 Subject: [PATCH 05/52] feat: add tidb into query engine tests --- .../tests/new/interactive_tx.rs | 5 ++-- .../query-engine-tests/tests/new/occ.rs | 6 ++--- .../new/ref_actions/on_delete/no_action.rs | 4 +-- .../new/ref_actions/on_delete/restrict.rs | 8 +++--- .../new/ref_actions/on_delete/set_default.rs | 8 +++--- .../new/ref_actions/on_update/restrict.rs | 24 ++++++++--------- .../new/ref_actions/on_update/set_default.rs | 8 +++--- .../new/ref_actions/on_update/set_null.rs | 4 +-- .../tests/new/regressions/prisma_10935.rs | 2 +- .../tests/new/regressions/prisma_7434.rs | 2 +- .../queries/aggregation/group_by_having.rs | 2 +- .../queries/batch/in_selection_batching.rs | 26 +++++++++++++------ .../queries/batch/transactional_batch.rs | 5 ++-- .../filters/extended_relation_filters.rs | 2 +- .../queries/filters/filter_regression.rs | 19 ++++++++++---- .../tests/queries/filters/json_filters.rs | 4 +-- .../tests/queries/filters/self_relation.rs | 23 +++++++++------- .../order_by_aggregation.rs | 2 +- .../order_by_dependent.rs | 4 +-- .../order_by_dependent_pagination.rs | 6 ++--- .../order_by_relevance.rs | 16 ++++++------ .../queries/simple/multi_field_unique.rs | 2 +- .../tests/raw/sql/typed_output.rs | 2 +- .../tests/writes/data_types/bytes.rs | 2 +- .../writes/data_types/native_types/mysql.rs | 2 +- .../tests/writes/ids/byoid.rs | 10 +++---- .../compound_fks_mixed_requiredness.rs | 2 +- .../writes/top_level_mutations/update.rs | 2 +- .../writes/top_level_mutations/update_many.rs | 2 +- 29 files changed, 115 insertions(+), 89 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs index 048c606477dc..31b1c938df97 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs @@ -426,7 +426,8 @@ mod itx_isolation { use query_engine_tests::*; // All (SQL) connectors support serializable. - #[connector_test(exclude(MongoDb))] + // TiDB support snapshot isolation, but didn't support serializable isolation. + #[connector_test(exclude(MongoDb, TiDB))] async fn basic_serializable(mut runner: Runner) -> TestResult<()> { let tx_id = runner.start_tx(5000, 5000, Some("Serializable".to_owned())).await?; runner.set_active_tx(tx_id.clone()); @@ -450,7 +451,7 @@ mod itx_isolation { #[connector_test(exclude(MongoDb))] async fn casing_doesnt_matter(mut runner: Runner) -> TestResult<()> { - let tx_id = runner.start_tx(5000, 5000, Some("sErIaLiZaBlE".to_owned())).await?; + let tx_id = runner.start_tx(5000, 5000, Some("rEpEaTaBlErEaD".to_owned())).await?; runner.set_active_tx(tx_id.clone()); let res = runner.commit_tx(tx_id).await?; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs index 242ff691d9ec..d79f732c4ad1 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs @@ -112,7 +112,7 @@ mod occ { assert_eq!(booked_user_id, found_booked_user_id); } - #[connector_test(schema(occ_simple), exclude(MongoDB, CockroachDb))] + #[connector_test(schema(occ_simple), exclude(MongoDB, CockroachDb, TiDB))] async fn occ_update_many_test(runner: Runner) -> TestResult<()> { let runner = Arc::new(runner); @@ -127,7 +127,7 @@ mod occ { Ok(()) } - #[connector_test(schema(occ_simple), exclude(CockroachDb))] + #[connector_test(schema(occ_simple), exclude(CockroachDb, TiDB))] async fn occ_update_test(runner: Runner) -> TestResult<()> { let runner = Arc::new(runner); @@ -158,7 +158,7 @@ mod occ { Ok(()) } - #[connector_test(schema(occ_simple))] + #[connector_test(schema(occ_simple), exclude(TiDB))] async fn occ_delete_test(runner: Runner) -> TestResult<()> { let runner = Arc::new(runner); diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs index c921f1090022..579e67dea1c7 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs @@ -54,7 +54,7 @@ mod one2one_req { #[test_suite( suite = "noaction_onD_1to1_opt", schema(optional), - exclude(Postgres, Sqlite, MongoDb) + exclude(Postgres, Sqlite, MongoDb, TiDB) )] mod one2one_opt { fn optional() -> String { @@ -251,7 +251,7 @@ mod one2many_req { #[test_suite( suite = "noaction_onD_1toM_opt", schema(optional), - exclude(Postgres, Sqlite, MongoDb) + exclude(Postgres, Sqlite, MongoDb, TiDB) )] mod one2many_opt { fn optional() -> String { diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/restrict.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/restrict.rs index f619ec0af1fd..f63b347bd4e1 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/restrict.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/restrict.rs @@ -31,7 +31,7 @@ mod one2one_req { ); match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, "mutation { deleteOneParent(where: { id: 1 }) { id }}", 2014, @@ -77,7 +77,7 @@ mod one2one_opt { ); match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, "mutation { deleteOneParent(where: { id: 1 }) { id }}", 2014, @@ -184,7 +184,7 @@ mod one2many_req { ); match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, "mutation { deleteOneParent(where: { id: 1 }) { id }}", 2014, @@ -256,7 +256,7 @@ mod one2many_opt { ); match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, "mutation { deleteOneParent(where: { id: 1 }) { id }}", 2014, diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/set_default.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/set_default.rs index d4aa49116ea0..6625ce7cd058 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/set_default.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/set_default.rs @@ -2,7 +2,7 @@ use indoc::indoc; use query_engine_tests::*; -#[test_suite(suite = "setdefault_onD_1to1_req", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onD_1to1_req", exclude(MongoDb, MySQL, TiDB))] mod one2one_req { fn required_with_default() -> String { let schema = indoc! { @@ -103,7 +103,7 @@ mod one2one_req { } } -#[test_suite(suite = "setdefault_onD_1to1_opt", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onD_1to1_opt", exclude(MongoDb, MySQL, TiDB))] mod one2one_opt { fn optional_with_default() -> String { let schema = indoc! { @@ -206,7 +206,7 @@ mod one2one_opt { } } -#[test_suite(suite = "setdefault_onD_1toM_req", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onD_1toM_req", exclude(MongoDb, MySQL, TiDB))] mod one2many_req { fn required_with_default() -> String { let schema = indoc! { @@ -307,7 +307,7 @@ mod one2many_req { } } -#[test_suite(suite = "setdefault_onD_1toM_opt", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onD_1toM_opt", exclude(MongoDb, MySQL, TiDB))] mod one2many_opt { fn optional_with_default() -> String { let schema = indoc! { diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/restrict.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/restrict.rs index 5d4a08b2b979..ca379d7fa2ba 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/restrict.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/restrict.rs @@ -32,7 +32,7 @@ mod one2one_req { let query = r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -57,7 +57,7 @@ mod one2one_req { let query = r#"mutation { updateManyParent(where: { id: 1 }, data: { uniq: "u1" }) { count }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -82,7 +82,7 @@ mod one2one_req { let query = r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, name: "Bob", uniq: "1", child: { create: { id: 1 }} }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -138,7 +138,7 @@ mod one2one_opt { let query = r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -163,7 +163,7 @@ mod one2one_opt { let query = r#"mutation { updateManyParent(where: { id: 1 }, data: { uniq: "u1" }) { count }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -188,7 +188,7 @@ mod one2one_opt { let query = r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, name: "Bob", uniq: "1", child: { create: { id: 1 }} }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -244,7 +244,7 @@ mod one2many_req { let query = r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -269,7 +269,7 @@ mod one2many_req { let query = r#"mutation { updateManyParent(where: { id: 1 }, data: { uniq: "u1" }) { count }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -294,7 +294,7 @@ mod one2many_req { let query = r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, name: "Bob", uniq: "1", children: { create: { id: 1 }} }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -386,7 +386,7 @@ mod one2many_opt { let query = r#"mutation { updateOneParent(where: { id: 1 }, data: { uniq: "u1" }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -411,7 +411,7 @@ mod one2many_opt { let query = r#"mutation { updateManyParent(where: { id: 1 }, data: { uniq: "u1" }) { count }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -436,7 +436,7 @@ mod one2many_opt { let query = r#"mutation { upsertOneParent(where: { id: 1 }, update: { uniq: "u1" }, create: { id: 1, name: "Bob", uniq: "1", children: { create: { id: 1 }} }) { id }}"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_default.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_default.rs index 270bb927c265..5b4e214895d0 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_default.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_default.rs @@ -2,7 +2,7 @@ use indoc::indoc; use query_engine_tests::*; -#[test_suite(suite = "setdefault_onU_1to1_req", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onU_1to1_req", exclude(MongoDb, MySQL, TiDB))] mod one2one_req { fn required_with_default() -> String { let schema = indoc! { @@ -105,7 +105,7 @@ mod one2one_req { } } -#[test_suite(suite = "setdefault_onU_1to1_opt", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onU_1to1_opt", exclude(MongoDb, MySQL, TiDB))] mod one2one_opt { fn optional_with_default() -> String { let schema = indoc! { @@ -210,7 +210,7 @@ mod one2one_opt { } } -#[test_suite(suite = "setdefault_onU_1toM_req", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onU_1toM_req", exclude(MongoDb, MySQL, TiDB))] mod one2many_req { fn required_with_default() -> String { let schema = indoc! { @@ -313,7 +313,7 @@ mod one2many_req { } } -#[test_suite(suite = "setdefault_onU_1toM_opt", exclude(MongoDb, MySQL))] +#[test_suite(suite = "setdefault_onU_1toM_opt", exclude(MongoDb, MySQL, TiDB))] mod one2many_opt { fn optional_with_default() -> String { let schema = indoc! { diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_null.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_null.rs index 9487f4e774df..e8aeb372d38f 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_null.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_update/set_null.rs @@ -259,7 +259,7 @@ mod one2one_opt { let query = r#"mutation { updateOneA(where: { id: 1 }, data: { b_id: 2 }) { id } }"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, @@ -759,7 +759,7 @@ mod one2many_opt { let query = r#"mutation { updateOneA(where: { id: 1 }, data: { b_id: 2 }) { id } }"#; match runner.connector_version() { - ConnectorVersion::MongoDb(_) => assert_error!( + ConnectorVersion::MongoDb(_) | ConnectorVersion::TiDB => assert_error!( runner, query, 2014, diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_10935.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_10935.rs index 13e8c83626a9..95be59ee43e2 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_10935.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_10935.rs @@ -1,6 +1,6 @@ use query_engine_tests::*; -#[test_suite(schema(schema), only(MySql))] +#[test_suite(schema(schema), only(MySql, TiDB))] mod prisma_ref_integrity { fn schema() -> String { let schema = indoc! { diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs index 3471f0c2d72c..b71ed4a09f0b 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs @@ -1,6 +1,6 @@ use query_engine_tests::*; -#[test_suite(schema(autoinc_id), capabilities(CreateMany, AutoIncrement), exclude(CockroachDb))] +#[test_suite(schema(autoinc_id), capabilities(CreateMany, AutoIncrement), exclude(CockroachDb, TiDB))] mod not_in_batching { use query_engine_tests::Runner; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/aggregation/group_by_having.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/aggregation/group_by_having.rs index e04ebd5869e0..98f5de52010a 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/aggregation/group_by_having.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/aggregation/group_by_having.rs @@ -42,7 +42,7 @@ mod aggr_group_by_having { _sum { int } } }"#, - MongoDb(_) => vec![ + MongoDb(_) | TiDB => vec![ r#"{"data":{"groupByTestModel":[{"string":"group2","int":5,"_count":{"_all":1},"_sum":{"int":5}},{"string":"group1","int":5,"_count":{"_all":1},"_sum":{"int":5}}]}}"#, r#"{"data":{"groupByTestModel":[{"string":"group1","int":5,"_count":{"_all":1},"_sum":{"int":5}},{"string":"group2","int":5,"_count":{"_all":1},"_sum":{"int":5}}]}}"# ], diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs index 36c14f275773..a3e2e0369989 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs @@ -39,13 +39,23 @@ mod isb { async fn in_more_items(runner: Runner) -> TestResult<()> { create_test_data(&runner).await?; - insta::assert_snapshot!( - run_query!(&runner, indoc! { r#" - query { - findManyA(where: { id: { in: [5,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,1,2,3,4,5,6] }}) { id } - }"# }), - @r###"{"data":{"findManyA":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5}]}}"### - ); + if matches!(runner.connector(), ConnectorTag::TiDB(_)) { + insta::assert_snapshot!( + run_query!(&runner, indoc! { r#" + query { + findManyA(where: { id: { in: [5,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,1,2,3,4,5,6] }}) { id } + }"# }), + @r###"{"data":{"findManyA":[{"id":5},{"id":4},{"id":3},{"id":2},{"id":1}]}}"### + ); + } else { + insta::assert_snapshot!( + run_query!(&runner, indoc! { r#" + query { + findManyA(where: { id: { in: [5,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,1,2,3,4,5,6] }}) { id } + }"# }), + @r###"{"data":{"findManyA":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5}]}}"### + ); + } Ok(()) } @@ -82,7 +92,7 @@ mod isb { Ok(()) } - #[connector_test(exclude(MongoDb))] + #[connector_test(exclude(MongoDb, TiDB))] async fn order_by_aggregation_should_fail(runner: Runner) -> TestResult<()> { create_test_data(&runner).await?; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs index 580b9f371017..c94f12e058b6 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs @@ -4,6 +4,7 @@ use query_engine_tests::*; mod transactional { use indoc::indoc; use query_engine_tests::run_query; + use query_tests_setup::Runner; fn schema() -> String { let schema = indoc! { @@ -89,7 +90,7 @@ mod transactional { Ok(()) } - #[connector_test(exclude(MongoDb))] + #[connector_test(exclude(MongoDb, TiDB))] async fn valid_isolation_level(runner: Runner) -> TestResult<()> { let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()]; @@ -100,7 +101,7 @@ mod transactional { Ok(()) } - #[connector_test(exclude(MongoDb))] + #[connector_test(exclude(MongoDb, TiDB))] async fn invalid_isolation_level(runner: Runner) -> TestResult<()> { let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()]; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/extended_relation_filters.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/extended_relation_filters.rs index 8dec5383fd0a..892993381b12 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/extended_relation_filters.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/extended_relation_filters.rs @@ -90,7 +90,7 @@ mod ext_rel_filters { } // MySql is case insensitive and Postgres case sensitive - #[connector_test(only(MySQL))] + #[connector_test(only(MySQL, TiDB))] async fn mysql_rel1_many_filters(runner: Runner) -> TestResult<()> { test_data(&runner).await?; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs index d3adaab1ed8d..f6276f202509 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs @@ -5,7 +5,7 @@ use query_engine_tests::*; #[test_suite(schema(schema))] mod fr_one_to_m { use indoc::indoc; - use query_engine_tests::run_query; + use query_engine_tests::{is_one_of, run_query}; fn schema() -> String { let schema = indoc! { " @@ -65,10 +65,19 @@ mod fr_one_to_m { @r###"{"data":{"findManyCompany":[{"id":135}]}}"### ); - insta::assert_snapshot!( - run_query!(&runner, r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#), - @r###"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"### - ); + match runner.connector_version() { + ConnectorVersion::TiDB => is_one_of!( + run_query!(&runner, r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#), + vec![ + r#"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"#, + r#"{"data":{"findManyLocation":[{"id":314},{"id":311}]}}"# + ] + ), + _ => insta::assert_snapshot!( + run_query!(&runner, r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#), + @r###"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"### + ), + }; Ok(()) } diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs index 701f7bf99544..63e9db671b87 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs @@ -111,7 +111,7 @@ mod json_filters { Ok(()) } - #[connector_test(capabilities(JsonFilteringJsonPath), only(MySql(5.7), MySql(8)))] + #[connector_test(capabilities(JsonFilteringJsonPath), only(MySql(5.7), MySql(8), TiDB))] async fn extract_json_path(runner: Runner) -> TestResult<()> { create_row(&runner, 1, r#"{ \"a\": { \"b\": \"c\" } }"#, false).await?; create_row(&runner, 2, r#"{ \"a\": { \"b\": [1, 2, 3] } }"#, false).await?; @@ -905,7 +905,7 @@ mod json_filters { fn json_path(runner: &Runner) -> &'static str { match runner.connector_version() { ConnectorVersion::Postgres(_) | ConnectorVersion::CockroachDb => r#"path: ["a", "b"]"#, - ConnectorVersion::MySql(_) => r#"path: "$.a.b""#, + ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => r#"path: "$.a.b""#, x => unreachable!("JSON filtering is not supported on {:?}", x), } } diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/self_relation.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/self_relation.rs index fe1627a85cfa..7ef41bac289c 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/self_relation.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/self_relation.rs @@ -3,7 +3,7 @@ use query_engine_tests::*; #[test_suite(schema(schema))] mod self_relation_filters { use indoc::indoc; - use query_engine_tests::{assert_error, run_query}; + use query_engine_tests::{assert_error, match_connector_result, run_query}; fn schema() -> String { let schema = indoc! { @@ -111,15 +111,20 @@ mod self_relation_filters { async fn one2one_null(runner: Runner) -> TestResult<()> { test_data(&runner).await?; - insta::assert_snapshot!( - run_query!(&runner, indoc! { r#" - query { - findManySong(where: { creator: { is: { wife: { is: null }}}}) { - title + match_connector_result!( + &runner, + indoc! { r#" + query { + findManySong(where: { creator: { is: { wife: { is: null }}}}) { + title + } } - } - "# }), - @r###"{"data":{"findManySong":[{"title":"Bicycle"},{"title":"Gasag"}]}}"### + "# }, + TiDB => vec![ + r###"{"data":{"findManySong":[{"title":"Bicycle"},{"title":"Gasag"}]}}"###, + r###"{"data":{"findManySong":[{"title":"Gasag"},{"title":"Bicycle"}]}}"### + ], + _ => vec![r###"{"data":{"findManySong":[{"title":"Bicycle"},{"title":"Gasag"}]}}"###] ); Ok(()) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_aggregation.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_aggregation.rs index 0116cb8ff995..f4bd307dd9de 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_aggregation.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_aggregation.rs @@ -267,7 +267,7 @@ mod order_by_aggr { } } }"#, - Postgres(_) | MySql(_) => vec![ + Postgres(_) | MySql(_) | TiDB => vec![ r#"{"data":{"findManyPost":[{"id":1,"user":{"name":"Alice","categories":[{"name":"Startup"}]}},{"id":2,"user":{"name":"Bob","categories":[{"name":"Computer Science"},{"name":"Music"}]}},{"id":3,"user":{"name":"Bob","categories":[{"name":"Computer Science"},{"name":"Music"}]}}]}}"#, r#"{"data":{"findManyPost":[{"id":1,"user":{"name":"Alice","categories":[{"name":"Startup"}]}},{"id":3,"user":{"name":"Bob","categories":[{"name":"Computer Science"},{"name":"Music"}]}},{"id":2,"user":{"name":"Bob","categories":[{"name":"Computer Science"},{"name":"Music"}]}}]}}"# ], diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent.rs index 4c456dd4a72d..6339c8c81c6d 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent.rs @@ -244,7 +244,7 @@ mod order_by_dependent { } }"#, MongoDb(_) | Sqlite => vec![r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#], - MySql(_) | CockroachDb => vec![ + MySql(_) | CockroachDb | TiDB => vec![ r#"{"data":{"findManyModelA":[{"id":4,"b":null},{"id":3,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#, r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#, ], @@ -276,7 +276,7 @@ mod order_by_dependent { } }"#, MongoDb(_) | Sqlite => vec![r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#], - MySql(_) | CockroachDb => vec![ + MySql(_) | CockroachDb | TiDB => vec![ r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":4,"b":null},{"id":3,"b":null}]}}"#, r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#, ], diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent_pagination.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent_pagination.rs index 1e855f68403d..365fed5edfbe 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent_pagination.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_dependent_pagination.rs @@ -97,7 +97,7 @@ mod order_by_dependent_pag { } }"#, // Depends on how null values are handled. - MongoDb(_) | Sqlite | MySql(_) | CockroachDb => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"id":1}},{"id":2,"b":{"id":2}}]}}"#], + MongoDb(_) | Sqlite | MySql(_) | CockroachDb | TiDB => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"id":1}},{"id":2,"b":{"id":2}}]}}"#], _ => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"id":1}},{"id":2,"b":{"id":2}},{"id":3,"b":null}]}}"#] ); @@ -166,7 +166,7 @@ mod order_by_dependent_pag { } }"#, // Depends on how null values are handled. - MongoDb(_) | Sqlite | MySql(_) | CockroachDb => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}}]}}"#], + MongoDb(_) | Sqlite | MySql(_) | CockroachDb | TiDB => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}}]}}"#], _ => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}},{"id":2,"b":{"c":null}},{"id":3,"b":null}]}}"#] ); @@ -248,7 +248,7 @@ mod order_by_dependent_pag { } }"#, // Depends on how null values are handled. - MongoDb(_) | MySql(_) | Sqlite | CockroachDb => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#], + MongoDb(_) | MySql(_) | Sqlite | CockroachDb | TiDB => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#], _ => vec![r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":3,"b":null},{"id":4,"b":null}]}}"#] ); diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_relevance.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_relevance.rs index 7525179762eb..cc38242187af 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_relevance.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/order_and_pagination/order_by_relevance.rs @@ -20,14 +20,14 @@ async fn on_single_field(runner: Runner) -> TestResult<()> { &runner, r#"{ findManyTestModel(orderBy: { _relevance: { fields: fieldA, search: "developer", sort: desc } }) { id } }"#, // For MySql id 3 and id 1 row have the same ranking score so they are switched between position 2 and 3 - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":2},{"id":3},{"id":1}]}}"#, r#"{"data":{"findManyTestModel":[{"id":2},{"id":1},{"id":3}]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":2},{"id":3},{"id":1}]}}"#, r#"{"data":{"findManyTestModel":[{"id":2},{"id":1},{"id":3}]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":2},{"id":1},{"id":3}]}}"#] ); match_connector_result!( &runner, r#"{ findManyTestModel(orderBy: { _relevance: { fields: fieldA, search: "developer", sort: asc } }) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":1},{"id":3},{"id":2}]}}"#, r#"{"data":{"findManyTestModel":[{"id":3},{"id":1},{"id":2}]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":1},{"id":3},{"id":2}]}}"#, r#"{"data":{"findManyTestModel":[{"id":3},{"id":1},{"id":2}]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":1},{"id":3},{"id":2}]}}"#] ); @@ -40,14 +40,14 @@ async fn on_single_nullable_field(runner: Runner) -> TestResult<()> { match_connector_result!( &runner, r#"{ findManyTestModel(orderBy: { _relevance: { fields: fieldC, search: "developer", sort: desc } }) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":3},{"id":1},{"id":2}]}}"#, r#"{"data":{"findManyTestModel":[{"id":3},{"id":2},{"id":1}]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":3},{"id":1},{"id":2}]}}"#, r#"{"data":{"findManyTestModel":[{"id":3},{"id":2},{"id":1}]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":3},{"id":1},{"id":2}]}}"#] ); match_connector_result!( &runner, r#"{ findManyTestModel(orderBy: { _relevance: { fields: fieldC, search: "developer", sort: asc } }) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[{"id":2},{"id":1},{"id":3}]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[{"id":2},{"id":1},{"id":3}]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":1},{"id":2},{"id":3}]}}"#] ); @@ -198,7 +198,7 @@ async fn on_single_field_with_pagination(runner: Runner) -> TestResult<()> { take: 1, orderBy: { _relevance: { fields: fieldA, search: "developer", sort: desc } } ) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":3}]}}"#] ); @@ -219,7 +219,7 @@ async fn on_single_field_with_pagination(runner: Runner) -> TestResult<()> { take: 1, orderBy: { _relevance: { fields: fieldA, search: "developer", sort: asc } } ) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[{"id":2}]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[{"id":2}]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":3}]}}"#] ); @@ -246,7 +246,7 @@ async fn on_single_nullable_field_with_pagination(runner: Runner) -> TestResult< take: 1, orderBy: { _relevance: { fields: fieldC, search: "developer", sort: desc } } ) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":2}]}}"#, r#"{"data":{"findManyTestModel":[]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":2}]}}"#, r#"{"data":{"findManyTestModel":[]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":2}]}}"#] ); @@ -266,7 +266,7 @@ async fn on_single_nullable_field_with_pagination(runner: Runner) -> TestResult< skip: 1, orderBy: { _relevance: { fields: fieldC, search: "developer", sort: asc } } ) { id } }"#, - MySql(_) => vec![r#"{"data":{"findManyTestModel":[{"id":2},{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[{"id":3}]}}"#], + MySql(_) | TiDB => vec![r#"{"data":{"findManyTestModel":[{"id":2},{"id":3}]}}"#, r#"{"data":{"findManyTestModel":[{"id":3}]}}"#], _ => vec![r#"{"data":{"findManyTestModel":[{"id":2},{"id":3}]}}"#] ); diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/simple/multi_field_unique.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/simple/multi_field_unique.rs index 626c2ee414ee..bf7175e60b47 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/simple/multi_field_unique.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/simple/multi_field_unique.rs @@ -176,7 +176,7 @@ mod multi_field_unique { schema.to_owned() } - #[connector_test(schema(many_unique_fields), exclude(MySQL))] + #[connector_test(schema(many_unique_fields), exclude(MySQL, TiDB))] async fn ludicrous_fields(runner: Runner) -> TestResult<()> { create_user( &runner, diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/raw/sql/typed_output.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/raw/sql/typed_output.rs index bc11be656f4d..b84b2d9f9ea3 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/raw/sql/typed_output.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/raw/sql/typed_output.rs @@ -215,7 +215,7 @@ mod typed_output { schema.to_owned() } - #[connector_test(schema(schema_mysql), only(MySql(5.7), MySql(8)))] + #[connector_test(schema(schema_mysql), only(MySql(5.7), MySql(8), TiDB))] async fn all_scalars_mysql(runner: Runner) -> TestResult<()> { create_row( &runner, diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/bytes.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/bytes.rs index a89bafd4c7ed..d9165665ac4c 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/bytes.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/bytes.rs @@ -77,7 +77,7 @@ mod bytes { Ok(()) } - #[connector_test(schema(bytes_id), exclude(MySQL, SqlServer))] + #[connector_test(schema(bytes_id), exclude(MySQL, TiDB, SqlServer))] async fn byte_id_coercion(runner: Runner) -> TestResult<()> { insta::assert_snapshot!( run_query!(runner, r#" diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/native_types/mysql.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/native_types/mysql.rs index c29b12d5b73f..c9e3483fcd77 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/native_types/mysql.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/data_types/native_types/mysql.rs @@ -1,6 +1,6 @@ use query_engine_tests::*; -#[test_suite(only(Mysql))] +#[test_suite(only(Mysql, TiDB))] mod mysql { use indoc::indoc; use query_engine_tests::run_query; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs index 2f2b39027040..7acce0fa25ee 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs @@ -1,6 +1,6 @@ use query_engine_tests::*; -#[test_suite(only(MySql, Postgres, Sqlite, Vitess))] +#[test_suite(only(MySql, Postgres, Sqlite, Vitess, TiDB))] // bring_your_own_id mod byoid { use indoc::indoc; @@ -55,7 +55,7 @@ mod byoid { ); let error_target = match runner.connector_version() { - query_engine_tests::ConnectorVersion::MySql(_) => "constraint: `PRIMARY`", + query_engine_tests::ConnectorVersion::MySql(_) | query_engine_tests::ConnectorVersion::TiDB => "constraint: `PRIMARY`", query_engine_tests::ConnectorVersion::Vitess(_) => "(not available)", _ => "fields: (`id`)", }; @@ -83,7 +83,7 @@ mod byoid { ); let error_target = match runner.connector_version() { - ConnectorVersion::MySql(_) => "constraint: `PRIMARY`", + ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => "constraint: `PRIMARY`", ConnectorVersion::Vitess(_) => "(not available)", _ => "fields: (`id`)", }; @@ -141,7 +141,7 @@ mod byoid { ); let error_target = match runner.connector_version() { - ConnectorVersion::MySql(_) => "constraint: `PRIMARY`", + ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => "constraint: `PRIMARY`", ConnectorVersion::Vitess(_) => "(not available)", _ => "fields: (`id`)", }; @@ -169,7 +169,7 @@ mod byoid { ); let error_target = match runner.connector_version() { - ConnectorVersion::MySql(_) => "constraint: `PRIMARY`", + ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => "constraint: `PRIMARY`", ConnectorVersion::Vitess(_) => "(not available)", _ => "fields: (`id`)", }; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs index 696a3f55b1e7..43e599fb0a9d 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs @@ -29,7 +29,7 @@ mod compound_fks { } // "A One to Many relation with mixed requiredness" should "be writable and readable" - #[connector_test(exclude(MySql(5.6), MongoDb))] + #[connector_test(exclude(MySql(5.6), MongoDb, TiDB))] async fn one2m_mix_required_writable_readable(runner: Runner) -> TestResult<()> { // Setup user insta::assert_snapshot!( diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs index 16c3dd60b5f0..0fbbf459b3ef 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs @@ -714,7 +714,7 @@ mod json_update { Ok(()) } - #[connector_test(capabilities(AdvancedJsonNullability))] + #[connector_test(capabilities(AdvancedJsonNullability), exclude(TiDB))] async fn update_json_adv(runner: Runner) -> TestResult<()> { insta::assert_snapshot!( run_query!(&runner, r#"mutation { createOneTestModel(data: { id: 1 }) { json }}"#), diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs index af48a96c7cbb..a4c9d85d643e 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs @@ -298,7 +298,7 @@ mod update_many { let count = &res["data"]["updateManyTestModel"]["count"]; // MySql does not count incrementing a null so the count is different - if !matches!(runner.connector(), ConnectorTag::MySql(_)) { + if !matches!(runner.connector(), ConnectorTag::MySql(_)) && !matches!(runner.connector(), ConnectorTag::TiDB(_)) { assert_eq!(count, 3); } From 95504db008d9c5061d4f4f19077ac36b04cd6821 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 27 Oct 2022 01:37:32 +0800 Subject: [PATCH 06/52] fix ci --- .../query-tests-setup/src/connector_tag/tidb.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 6fcbd2a9757b..797873523001 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -50,20 +50,13 @@ impl ConnectorTagInterface for TiDBConnectorTag { fn connection_string( &self, database: &str, - is_ci: bool, + _: bool, _is_multi_schema: bool, _: Option<&'static str>, ) -> String { - // Use the same database and schema name for CockroachDB - unfortunately CockroachDB - // can't handle 1 schema per test in a database well at this point in time. - if is_ci { - format!("mysql://root@localhost:4000/{}", database) - } else { - format!("mysql://root@localhost:4000/{}", database) - } + format!("mysql://root@localhost:4000/{}", database) } - fn capabilities(&self) -> &[ConnectorCapability] { &self.capabilities } @@ -96,5 +89,5 @@ impl TiDBConnectorTag { } fn tidb_capabilities() -> Vec { - (&CAPABILITIES).to_vec().to_owned() + (CAPABILITIES).to_vec() } From 49ab8b879e4778a76fe9bfa2c85c8e10afd27b10 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 27 Oct 2022 01:39:45 +0800 Subject: [PATCH 07/52] fix ci --- .../migration-engine-tests/tests/migrations/mysql.rs | 2 +- .../tests/new/regressions/prisma_7434.rs | 6 +++++- .../tests/queries/filters/filter_regression.rs | 7 +++++-- .../query-engine-tests/tests/writes/ids/byoid.rs | 4 +++- .../tests/writes/top_level_mutations/update_many.rs | 3 ++- .../query-tests-setup/src/connector_tag/mod.rs | 4 ++-- .../query-tests-setup/src/connector_tag/tidb.rs | 11 ++--------- 7 files changed, 20 insertions(+), 17 deletions(-) diff --git a/migration-engine/migration-engine-tests/tests/migrations/mysql.rs b/migration-engine/migration-engine-tests/tests/migrations/mysql.rs index 38bd40c6d99e..1b79fe48dba7 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/mysql.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/mysql.rs @@ -260,7 +260,7 @@ fn native_type_columns_can_be_created(api: TestApi) { "year(4) unsigned" } else { "year(4)" - } + }, ), ]; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs index b71ed4a09f0b..6a510253e894 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs @@ -1,6 +1,10 @@ use query_engine_tests::*; -#[test_suite(schema(autoinc_id), capabilities(CreateMany, AutoIncrement), exclude(CockroachDb, TiDB))] +#[test_suite( + schema(autoinc_id), + capabilities(CreateMany, AutoIncrement), + exclude(CockroachDb, TiDB) +)] mod not_in_batching { use query_engine_tests::Runner; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs index f6276f202509..875fbbad9eed 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/filter_regression.rs @@ -66,8 +66,11 @@ mod fr_one_to_m { ); match runner.connector_version() { - ConnectorVersion::TiDB => is_one_of!( - run_query!(&runner, r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"#), + ConnectorVersion::TiDB => is_one_of!( + run_query!( + &runner, + r#"query { findManyLocation(where: { company: { is: { id: { equals: 135 }}}}){ id }}"# + ), vec![ r#"{"data":{"findManyLocation":[{"id":311},{"id":314}]}}"#, r#"{"data":{"findManyLocation":[{"id":314},{"id":311}]}}"# diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs index 7acce0fa25ee..288996fa79a6 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/ids/byoid.rs @@ -55,7 +55,9 @@ mod byoid { ); let error_target = match runner.connector_version() { - query_engine_tests::ConnectorVersion::MySql(_) | query_engine_tests::ConnectorVersion::TiDB => "constraint: `PRIMARY`", + query_engine_tests::ConnectorVersion::MySql(_) | query_engine_tests::ConnectorVersion::TiDB => { + "constraint: `PRIMARY`" + } query_engine_tests::ConnectorVersion::Vitess(_) => "(not available)", _ => "fields: (`id`)", }; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs index a4c9d85d643e..fd62986d07b6 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update_many.rs @@ -298,7 +298,8 @@ mod update_many { let count = &res["data"]["updateManyTestModel"]["count"]; // MySql does not count incrementing a null so the count is different - if !matches!(runner.connector(), ConnectorTag::MySql(_)) && !matches!(runner.connector(), ConnectorTag::TiDB(_)) { + if !matches!(runner.connector(), ConnectorTag::MySql(_)) && !matches!(runner.connector(), ConnectorTag::TiDB(_)) + { assert_eq!(count, 3); } diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs index 28fbec3a4f12..6f52dcf840c5 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/mod.rs @@ -4,16 +4,16 @@ mod mysql; mod postgres; mod sql_server; mod sqlite; -mod vitess; mod tidb; +mod vitess; pub use mongodb::*; pub use mysql::*; pub use postgres::*; pub use sql_server::*; pub use sqlite::*; -pub use vitess::*; pub use tidb::*; +pub use vitess::*; use crate::{datamodel_rendering::DatamodelRenderer, TestConfig, TestError}; use cockroachdb::*; diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 797873523001..113b18aa685e 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -1,5 +1,5 @@ use super::*; -use crate::{SqlDatamodelRenderer}; +use crate::SqlDatamodelRenderer; const CAPABILITIES: &[ConnectorCapability] = &[ ConnectorCapability::Enums, @@ -47,13 +47,7 @@ impl ConnectorTagInterface for TiDBConnectorTag { Box::new(SqlDatamodelRenderer::new()) } - fn connection_string( - &self, - database: &str, - _: bool, - _is_multi_schema: bool, - _: Option<&'static str>, - ) -> String { + fn connection_string(&self, database: &str, _: bool, _is_multi_schema: bool, _: Option<&'static str>) -> String { format!("mysql://root@localhost:4000/{}", database) } @@ -72,7 +66,6 @@ impl ConnectorTagInterface for TiDBConnectorTag { fn relation_mode(&self) -> &'static str { "prisma" } - } impl TiDBConnectorTag { From cf3e8e3f2ce90854f902228a63cb607e63c5179a Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sun, 6 Nov 2022 21:55:00 +0800 Subject: [PATCH 08/52] fix: add interactive_tx testcase for TiDB cause TiDB doesn't support serializable isolation level --- .../tests/new/interactive_tx.rs | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs index 31b1c938df97..be6f947e7a68 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs @@ -425,8 +425,7 @@ mod interactive_tx { mod itx_isolation { use query_engine_tests::*; - // All (SQL) connectors support serializable. - // TiDB support snapshot isolation, but didn't support serializable isolation. + // All (SQL) connectors except TiDB support serializable. #[connector_test(exclude(MongoDb, TiDB))] async fn basic_serializable(mut runner: Runner) -> TestResult<()> { let tx_id = runner.start_tx(5000, 5000, Some("Serializable".to_owned())).await?; @@ -449,9 +448,9 @@ mod itx_isolation { Ok(()) } - #[connector_test(exclude(MongoDb))] + #[connector_test(exclude(MongoDb, TiDB))] async fn casing_doesnt_matter(mut runner: Runner) -> TestResult<()> { - let tx_id = runner.start_tx(5000, 5000, Some("rEpEaTaBlErEaD".to_owned())).await?; + let tx_id = runner.start_tx(5000, 5000, Some("sErIaLiZaBlE".to_owned())).await?; runner.set_active_tx(tx_id.clone()); let res = runner.commit_tx(tx_id).await?; @@ -503,4 +502,38 @@ mod itx_isolation { Ok(()) } + + // TiDB supports repeatable read isolation level, but doesn't support serializable isolation level. + #[connector_test(only(TiDB))] + async fn tidb_basic_repeatable_read(mut runner: Runner) -> TestResult<()> { + let tx_id = runner.start_tx(5000, 5000, Some("RepeatableRead".to_owned())).await?; + runner.set_active_tx(tx_id.clone()); + + insta::assert_snapshot!( + run_query!(&runner, r#"mutation { createOneTestModel(data: { id: 1 }) { id }}"#), + @r###"{"data":{"createOneTestModel":{"id":1}}}"### + ); + + let res = runner.commit_tx(tx_id).await?; + assert!(res.is_ok()); + runner.clear_active_tx(); + + insta::assert_snapshot!( + run_query!(&runner, r#"query { findManyTestModel { id field }}"#), + @r###"{"data":{"findManyTestModel":[{"id":1,"field":null}]}}"### + ); + + Ok(()) + } + + #[connector_test(only(TiDB))] + async fn tidb_casing_doesnt_matter(mut runner: Runner) -> TestResult<()> { + let tx_id = runner.start_tx(5000, 5000, Some("rEpEaTaBlErEaD".to_owned())).await?; + runner.set_active_tx(tx_id.clone()); + + let res = runner.commit_tx(tx_id).await?; + assert!(res.is_ok()); + + Ok(()) + } } From 0b3b241b8a5924d1f108d27b4a83865d8ab229da Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sun, 6 Nov 2022 21:55:31 +0800 Subject: [PATCH 09/52] fix: add introspect_tidb_non_prisma testcase for TiDB cause TiDB doesn't support point data type --- .../tests/identify_version/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs index 64605c245ea9..5d6c37d32ee7 100644 --- a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs @@ -340,3 +340,21 @@ async fn introspect_mssql_non_prisma_empty(api: &TestApi) -> TestResult { Ok(()) } + +// TiDB + +#[test_connector(tags(TiDB))] +async fn introspect_tidb_non_prisma(api: &TestApi) -> TestResult { + api.barrel() + .execute(|migration| { + migration.create_table("Book", |t| { + t.add_column("id", types::primary()); + t.inject_custom("location json"); + }); + }) + .await?; + + assert_eq!(Version::NonPrisma, api.introspect_version().await?); + + Ok(()) +} From a76d752066e9ec48d992ad38609913b4eef743a0 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sun, 6 Nov 2022 22:04:24 +0800 Subject: [PATCH 10/52] fix: not more skip update_json_adv testcase cause this issue has been fixed --- .../tests/writes/top_level_mutations/update.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs index 0fbbf459b3ef..16c3dd60b5f0 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/top_level_mutations/update.rs @@ -714,7 +714,7 @@ mod json_update { Ok(()) } - #[connector_test(capabilities(AdvancedJsonNullability), exclude(TiDB))] + #[connector_test(capabilities(AdvancedJsonNullability))] async fn update_json_adv(runner: Runner) -> TestResult<()> { insta::assert_snapshot!( run_query!(&runner, r#"mutation { createOneTestModel(data: { id: 1 }) { json }}"#), From 4cf3f51c309dde001d4825cf6a54918572264090 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sun, 6 Nov 2022 23:18:31 +0800 Subject: [PATCH 11/52] fix: not more skip not_in_batching testcase cause QUERY_BATCH_SIZE=10 is missing before --- .../query-engine-tests/tests/new/regressions/prisma_7434.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs index 6a510253e894..3471f0c2d72c 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_7434.rs @@ -1,10 +1,6 @@ use query_engine_tests::*; -#[test_suite( - schema(autoinc_id), - capabilities(CreateMany, AutoIncrement), - exclude(CockroachDb, TiDB) -)] +#[test_suite(schema(autoinc_id), capabilities(CreateMany, AutoIncrement), exclude(CockroachDb))] mod not_in_batching { use query_engine_tests::Runner; From 8177d21bfa7a5699437ae5d4915d946a0ed81f3b Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 7 Nov 2022 00:24:01 +0800 Subject: [PATCH 12/52] fix: revert changes in advisory_locking_works testcase --- .../tests/migrations/advisory_locking.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs b/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs index 08ab4c1245c0..20f0bf92deed 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/advisory_locking.rs @@ -33,7 +33,7 @@ fn advisory_locking_works(mut api: TestApi) { // We move the engines into the async block so they get dropped when they // are done with the request, releasing the lock as a consequence. async move { - first_me + second_me .apply_migrations(&migrations_directory) .send() .await @@ -41,7 +41,7 @@ fn advisory_locking_works(mut api: TestApi) { .into_output() }, async move { - second_me + first_me .apply_migrations(&migrations_directory_2) .send() .await From 3ef6694c8918133efc0b2e59393709e538fcf48d Mon Sep 17 00:00:00 2001 From: Mini256 Date: Tue, 8 Nov 2022 21:37:33 +0800 Subject: [PATCH 13/52] fix: add link for tidb_basic_repeatable_read testcase --- .../query-engine-tests/tests/new/interactive_tx.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs index be6f947e7a68..52526995d1a2 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/interactive_tx.rs @@ -504,6 +504,7 @@ mod itx_isolation { } // TiDB supports repeatable read isolation level, but doesn't support serializable isolation level. + // Link: https://docs.pingcap.com/tidb/stable/transaction-isolation-levels#tidb-transaction-isolation-levels #[connector_test(only(TiDB))] async fn tidb_basic_repeatable_read(mut runner: Runner) -> TestResult<()> { let tx_id = runner.start_tx(5000, 5000, Some("RepeatableRead".to_owned())).await?; From 179b7f5c0a813dfe39e034e1d48d37877cc3ac95 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 11 Nov 2022 12:32:20 +0800 Subject: [PATCH 14/52] fix: add comment for metadata_for_tidb_should_work testcase --- .../tests/rpc_calls/get_metadata_command_tests.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs b/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs index b5e396c161c8..6dca05e28adf 100644 --- a/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs +++ b/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs @@ -3,7 +3,7 @@ use introspection_engine_tests::{test_api::*, BarrelMigrationExecutor}; use pretty_assertions::assert_eq; use test_macros::test_connector; -#[test_connector(tags(Mysql), exclude(TiDB))] +#[test_connector(tags(Mysql))] async fn metadata_for_mysql_should_work(api: &TestApi) -> TestResult { setup(&api.barrel(), api.db_name()).await?; @@ -15,6 +15,11 @@ async fn metadata_for_mysql_should_work(api: &TestApi) -> TestResult { Ok(()) } +// Because the underlying storage structure is different, TiDB and MySQL InnoDB calculate DATA_LENGTH +// in different ways. +// For TiDB, DATA_LENGTH = TABLE_ROWS * the sum of storage lengths of the columns in the tuple. And +// the replicas of TiKV are not taken into account. +// Reference: https://docs.pingcap.com/tidb/stable/information-schema-tables#tables #[test_connector(tags(TiDB))] async fn metadata_for_tidb_should_work(api: &TestApi) -> TestResult { setup(&api.barrel(), api.schema_name()).await?; From 949008f5bcf1bd4a618901303547c4a1b546a67d Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sat, 12 Nov 2022 21:49:08 +0800 Subject: [PATCH 15/52] fix: remove exclude for safe_casts_with_existing_data_should_work testcase --- .../tests/native_types/mysql.rs | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs index 6cbd036e64d2..d5069deca70b 100644 --- a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs +++ b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs @@ -692,6 +692,22 @@ fn type_is_unsupported_mysql_5_6(ty: &str) -> bool { type_is_unsupported_mariadb(ty) } +fn type_cast_is_unsupported_tidb(from_type: &str, to_type: &str) -> bool { + (from_type == "Binary(8)" && to_type == "Bit(64)") + || (from_type == "Binary(8)" && to_type == "Char(64)") + || (from_type == "Binary(8)" && to_type == "VarChar(20)") + || (from_type == "Binary(8)" && to_type == "LongText") + || (from_type == "Binary(8)" && to_type == "MediumText") + || (from_type == "Binary(8)" && to_type == "TinyText") + || (from_type == "Binary(8)" && to_type == "Text") + || (from_type == "Char(10)" && to_type == "Blob") + || (from_type == "Char(10)" && to_type == "LongBlob") + || (from_type == "Char(10)" && to_type == "MediumBlob") + || (from_type == "Char(10)" && to_type == "TinyBlob") + || (from_type == "Date" && to_type == "Bit(64)") + || (from_type == "Year" && to_type == "Bit(64)") +} + fn filter_from_types(api: &TestApi, cases: Cases) -> Cow<'static, [Case]> { if api.is_mariadb() { return Cow::Owned( @@ -716,7 +732,7 @@ fn filter_from_types(api: &TestApi, cases: Cases) -> Cow<'static, [Case]> { cases.into() } -fn filter_to_types(api: &TestApi, to_types: &'static [&'static str]) -> Cow<'static, [&'static str]> { +fn filter_to_types(api: &TestApi, from_type: &&str, to_types: &'static [&'static str]) -> Cow<'static, [&'static str]> { if api.is_mariadb() { return Cow::Owned( to_types @@ -737,10 +753,21 @@ fn filter_to_types(api: &TestApi, to_types: &'static [&'static str]) -> Cow<'sta ); } + if api.is_tidb() { + let fty = from_type; + return Cow::Owned( + to_types + .iter() + .cloned() + .filter(|ty| !type_cast_is_unsupported_tidb(fty, ty)) + .collect(), + ); + } + to_types.into() } -#[test_connector(tags(Mysql), exclude(TiDB))] +#[test_connector(tags(Mysql))] fn safe_casts_with_existing_data_should_work(api: TestApi) { let connector = psl::builtin_connectors::MYSQL; let mut dm1 = String::with_capacity(256); @@ -752,7 +779,7 @@ fn safe_casts_with_existing_data_should_work(api: TestApi) { let span = tracing::info_span!("SafeCasts", from = %from_type, to = ?to_types); let _span = span.enter(); - let to_types = filter_to_types(&api, to_types); + let to_types = filter_to_types(&api, from_type, to_types); tracing::info!("initial migration"); @@ -785,7 +812,7 @@ fn safe_casts_with_existing_data_should_work(api: TestApi) { } } -#[test_connector(tags(Mysql), exclude(TiDB))] +#[test_connector(tags(Mysql))] fn risky_casts_with_existing_data_should_warn(api: TestApi) { let connector = psl::builtin_connectors::MYSQL; let mut dm1 = String::with_capacity(256); @@ -798,7 +825,7 @@ fn risky_casts_with_existing_data_should_warn(api: TestApi) { let span = tracing::info_span!("RiskyCasts", from = %from_type, to = ?to_types); let _span = span.enter(); - let to_types = filter_to_types(&api, to_types); + let to_types = filter_to_types(&api, from_type, to_types); tracing::info!("initial migration"); @@ -860,7 +887,7 @@ fn impossible_casts_with_existing_data_should_warn(api: TestApi) { let span = tracing::info_span!("ImpossibleCasts", from = %from_type, to = ?to_types); let _span = span.enter(); - let to_types = filter_to_types(&api, to_types); + let to_types = filter_to_types(&api, from_type, to_types); tracing::info!("initial migration"); From c4469be03df14e6c0e4bddadb949c7fe83d5e7fe Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sat, 12 Nov 2022 22:56:29 +0800 Subject: [PATCH 16/52] test: add testcase valid_isolation_level_tidb and no more exclude invalid_isolation_level testcase --- .../tests/queries/batch/transactional_batch.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs index c94f12e058b6..d8ba01e2d2da 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/transactional_batch.rs @@ -4,7 +4,6 @@ use query_engine_tests::*; mod transactional { use indoc::indoc; use query_engine_tests::run_query; - use query_tests_setup::Runner; fn schema() -> String { let schema = indoc! { @@ -101,7 +100,19 @@ mod transactional { Ok(()) } - #[connector_test(exclude(MongoDb, TiDB))] + // TiDB supports repeatable read isolation level, but doesn't support serializable isolation level. + #[connector_test(only(TiDB))] + async fn valid_isolation_level_tidb(runner: Runner) -> TestResult<()> { + let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()]; + + let batch_results = runner.batch(queries, true, Some("RepeatableRead".into())).await?; + + insta::assert_snapshot!(batch_results.to_string(), @r###"{"batchResult":[{"data":{"createOneModelB":{"id":1}}}]}"###); + + Ok(()) + } + + #[connector_test(exclude(MongoDb))] async fn invalid_isolation_level(runner: Runner) -> TestResult<()> { let queries = vec![r#"mutation { createOneModelB(data: { id: 1 }) { id }}"#.to_string()]; From b3d2d0951dd7d59e9d309a1bd05afed239a5caf0 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sun, 13 Nov 2022 18:22:36 +0800 Subject: [PATCH 17/52] fix: add comment for primary_key_migrations_do_not_cause_data_loss testcase --- .../migration-engine-tests/tests/existing_data/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration-engine/migration-engine-tests/tests/existing_data/mod.rs b/migration-engine/migration-engine-tests/tests/existing_data/mod.rs index 21de2dff83bf..5a5135843c05 100644 --- a/migration-engine/migration-engine-tests/tests/existing_data/mod.rs +++ b/migration-engine/migration-engine-tests/tests/existing_data/mod.rs @@ -779,6 +779,8 @@ fn set_default_current_timestamp_on_existing_column_works(api: TestApi) { } // exclude: there is a cockroach-specific test. It's unexecutable there. +// Ignore TiDB: TiDB Does not support modifying the Reorg-Data types on the primary key columns but +// supports modifying the Meta-Only types. (https://docs.pingcap.com/tidb/dev/sql-statement-modify-column#mysql-compatibility) #[test_connector(preview_features("referentialIntegrity"), exclude(CockroachDb, TiDB))] fn primary_key_migrations_do_not_cause_data_loss(api: TestApi) { let dm1 = r#" From 802aad7edb300057453fe68da589855f4ec35d6a Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sun, 13 Nov 2022 18:47:37 +0800 Subject: [PATCH 18/52] fix: include TiDB in the on_delete:no_action:delete_parent_violation testcases --- .../tests/new/ref_actions/on_delete/no_action.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs index 579e67dea1c7..f3429e5aae57 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/ref_actions/on_delete/no_action.rs @@ -126,7 +126,7 @@ mod one2one_opt { } /// Deleting the parent leaves the data in a integrity-violating state. - #[connector_test(only(MongoDb))] + #[connector_test(only(MongoDb, TiDB))] async fn delete_parent_violation(runner: Runner) -> TestResult<()> { insta::assert_snapshot!( run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, child: { create: { id: 1 }}}) { id }}"#), @@ -323,7 +323,7 @@ mod one2many_opt { } /// Deleting the parent leaves the data in a integrity-violating state. - #[connector_test(only(MongoDb))] + #[connector_test(only(MongoDb, TiDB))] async fn delete_parent_violation(runner: Runner) -> TestResult<()> { insta::assert_snapshot!( run_query!(&runner, r#"mutation { createOneParent(data: { id: 1, children: { create: { id: 1 }}}) { id }}"#), From c4caaf85f6e440cf4a39083ccc6ac13cc250aef5 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 18 Nov 2022 00:32:57 +0800 Subject: [PATCH 19/52] fix: merge introspect_tidb/mysql_non_prisma testcase --- .../tests/identify_version/mod.rs | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs index 5d6c37d32ee7..5005e61a0799 100644 --- a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs @@ -215,13 +215,13 @@ async fn introspect_postgres_prisma2(api: &TestApi) -> TestResult { //Mysql -#[test_connector(tags(Mysql), exclude(TiDB))] +#[test_connector(tags(Mysql))] async fn introspect_mysql_non_prisma(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { migration.create_table("Book", |t| { t.add_column("id", types::primary()); - t.inject_custom("location point"); + t.inject_custom("location json"); }); }) .await?; @@ -340,21 +340,3 @@ async fn introspect_mssql_non_prisma_empty(api: &TestApi) -> TestResult { Ok(()) } - -// TiDB - -#[test_connector(tags(TiDB))] -async fn introspect_tidb_non_prisma(api: &TestApi) -> TestResult { - api.barrel() - .execute(|migration| { - migration.create_table("Book", |t| { - t.add_column("id", types::primary()); - t.inject_custom("location json"); - }); - }) - .await?; - - assert_eq!(Version::NonPrisma, api.introspect_version().await?); - - Ok(()) -} From ab065a9e01bbee11f7fd4a46c4ff4b3b5c368415 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 5 Dec 2022 10:13:48 +0800 Subject: [PATCH 20/52] Update introspection-engine/introspection-engine-tests/tests/tables/mod.rs Co-authored-by: Jan Piotrowski --- .../introspection-engine-tests/tests/tables/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/introspection-engine/introspection-engine-tests/tests/tables/mod.rs b/introspection-engine/introspection-engine-tests/tests/tables/mod.rs index 58220b05b227..ed78bbc7c1e0 100644 --- a/introspection-engine/introspection-engine-tests/tests/tables/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/tables/mod.rs @@ -708,7 +708,7 @@ async fn expression_indexes_should_be_ignored_on_sqlite(api: &TestApi) -> TestRe Ok(()) } -// TiDB table names are case-insensitive by default, related pingcap/tidb#5714 +// TiDB table names are case-insensitive by default, related https://github.com/pingcap/tidb/issues/5714 #[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn casing_should_not_lead_to_mix_ups(api: &TestApi) -> TestResult { api.barrel() From d649e0b2a2bccef06e2db9278a4f43b167a78c8c Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 5 Dec 2022 12:05:34 +0800 Subject: [PATCH 21/52] Update migration-engine/migration-engine-tests/tests/migrations/id.rs Co-authored-by: Jan Piotrowski --- migration-engine/migration-engine-tests/tests/migrations/id.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration-engine/migration-engine-tests/tests/migrations/id.rs b/migration-engine/migration-engine-tests/tests/migrations/id.rs index 2ae9cbce9058..0cadf2400fd8 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/id.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/id.rs @@ -109,7 +109,7 @@ fn length_prefixed_compound_primary_key(api: TestApi) { // Ignoring TiDB, unsupported drop primary key when the table's pkIsHandle is true. // TODO: ignore because not possible on cockroachdb. We would need a multi-step process there. -#[test_connector(exclude(Vitess), exclude(CockroachDb, TiDB))] +#[test_connector(exclude(Vitess, CockroachDb, TiDB))] fn changing_the_type_of_an_id_field_must_work(api: TestApi) { let dm1 = r#" model A { From 52d7328031bd4f31886b78244bfd2f801ccd708c Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 5 Dec 2022 15:04:12 +0800 Subject: [PATCH 22/52] address comment --- .../tests/migrations/foreign_keys.rs | 2 ++ .../tests/migrations/id.rs | 2 +- .../tests/native_types/mysql.rs | 30 ++++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs b/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs index 06bcfae8f3a8..ce697d0cc583 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/foreign_keys.rs @@ -284,6 +284,8 @@ fn changing_a_foreign_key_constrained_column_from_nullable_to_required_and_back_ api.schema_push_w_datasource(dm).send().assert_green(); } +// Ignore TiDB, unsupported drop primary key when the table's pkIsHandle is true, +// which means we can't drop primary key when the table is using clustered index. #[test_connector(exclude(CockroachDb, TiDB))] fn changing_all_referenced_columns_of_foreign_key_works(api: TestApi) { let dm1 = r#" diff --git a/migration-engine/migration-engine-tests/tests/migrations/id.rs b/migration-engine/migration-engine-tests/tests/migrations/id.rs index 0cadf2400fd8..1d93666ad509 100644 --- a/migration-engine/migration-engine-tests/tests/migrations/id.rs +++ b/migration-engine/migration-engine-tests/tests/migrations/id.rs @@ -399,7 +399,7 @@ fn making_an_autoincrement_default_an_expression_then_autoincrement_again_works( }); } -// Ignoring TiDB, we can't drop column id with composite index covered or Primary Key covered now. +// Ignoring TiDB, unsupported drop primary key when the table is using clustered index. #[test_connector(exclude(CockroachDb, TiDB))] fn migrating_a_unique_constraint_to_a_primary_key_works(api: TestApi) { let dm = r#" diff --git a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs index c5433c502301..8c924f7c8279 100644 --- a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs +++ b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs @@ -693,21 +693,31 @@ fn type_is_unsupported_mysql_5_6(ty: &str) -> bool { } fn type_cast_is_unsupported_tidb(from_type: &str, to_type: &str) -> bool { + // Unsupported modify charset from utf8mb4 to binary. + if type_is_binary(from_type) && type_is_text(to_type) { + return true; + } + + if type_is_text(from_type) && type_is_binary(to_type) { + return true; + } + + // Unsupported modify column: change from original type date / year / binary to bit(64) is + // currently unsupported yet. (from_type == "Binary(8)" && to_type == "Bit(64)") - || (from_type == "Binary(8)" && to_type == "Char(64)") - || (from_type == "Binary(8)" && to_type == "VarChar(20)") - || (from_type == "Binary(8)" && to_type == "LongText") - || (from_type == "Binary(8)" && to_type == "MediumText") - || (from_type == "Binary(8)" && to_type == "TinyText") - || (from_type == "Binary(8)" && to_type == "Text") - || (from_type == "Char(10)" && to_type == "Blob") - || (from_type == "Char(10)" && to_type == "LongBlob") - || (from_type == "Char(10)" && to_type == "MediumBlob") - || (from_type == "Char(10)" && to_type == "TinyBlob") + || (from_type == "Binary(8)" && to_type == "Bit(32)") || (from_type == "Date" && to_type == "Bit(64)") || (from_type == "Year" && to_type == "Bit(64)") } +fn type_is_text(ty: &str) -> bool { + return ty.contains("Char") || ty.contains("Text") +} + +fn type_is_binary(ty: &str) -> bool { + return ty.contains("Blob") || ty.contains("Binary") +} + fn filter_from_types(api: &TestApi, cases: Cases) -> Cow<'static, [Case]> { if api.is_mariadb() { return Cow::Owned( From 7725134ae77723edccd12715def9ada3106c70bf Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 5 Dec 2022 17:54:34 +0800 Subject: [PATCH 23/52] test: add tidb in the matrix of GitHub action and use tidb v6.5.0-pre image --- .github/workflows/migration-engine.yml | 2 ++ .github/workflows/query-engine.yml | 3 +++ docker-compose.yml | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/migration-engine.yml b/.github/workflows/migration-engine.yml index 418247e9b97a..b7d0dfa24276 100644 --- a/.github/workflows/migration-engine.yml +++ b/.github/workflows/migration-engine.yml @@ -72,6 +72,8 @@ jobs: url: "mysql://root:prisma@localhost:3307" - name: mysql_mariadb url: "mysql://root:prisma@localhost:3308" + - name: tidb + url: "mysql://root@localhost:4000" - name: postgres9 url: "postgresql://postgres:prisma@localhost:5431" - name: postgres10 diff --git a/.github/workflows/query-engine.yml b/.github/workflows/query-engine.yml index 5fda136a9031..4578cfb8cfbd 100644 --- a/.github/workflows/query-engine.yml +++ b/.github/workflows/query-engine.yml @@ -35,6 +35,9 @@ jobs: single_threaded: false connector: "sqlserver" version: "2022" + - name: "tidb" + single_threaded: false + connector: "tidb" env: LOG_LEVEL: "info" diff --git a/docker-compose.yml b/docker-compose.yml index e46eeed86163..07a8c1dbec25 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -172,7 +172,7 @@ services: tmpfs: /var/lib/mariadb tidb: - image: pingcap/tidb:6.3 + image: pingcap/tidb:v6.5.0-pre restart: always platform: linux/x86_64 ports: From e7fe8b4e145dd0618cd03722820661ed2832ff31 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 01:10:59 +0800 Subject: [PATCH 24/52] fix testes --- .../tests/identify_version/mod.rs | 23 ++++++++++++-- .../rpc_calls/get_metadata_command_tests.rs | 2 +- .../tests/native_types/mysql.rs | 4 +-- .../queries/batch/in_selection_batching.rs | 30 +++++++------------ 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs index 5005e61a0799..90f4966d5b02 100644 --- a/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs +++ b/introspection-engine/introspection-engine-tests/tests/identify_version/mod.rs @@ -215,13 +215,14 @@ async fn introspect_postgres_prisma2(api: &TestApi) -> TestResult { //Mysql -#[test_connector(tags(Mysql))] +// Exclude TiDB, TiDB doesn't support `point` type. +#[test_connector(tags(Mysql), exclude(TiDB))] async fn introspect_mysql_non_prisma(api: &TestApi) -> TestResult { api.barrel() .execute(|migration| { migration.create_table("Book", |t| { t.add_column("id", types::primary()); - t.inject_custom("location json"); + t.inject_custom("location point"); }); }) .await?; @@ -340,3 +341,21 @@ async fn introspect_mssql_non_prisma_empty(api: &TestApi) -> TestResult { Ok(()) } + +// TiDB + +#[test_connector(tags(TiDB))] +async fn introspect_tidb_non_prisma(api: &TestApi) -> TestResult { + api.barrel() + .execute(|migration| { + migration.create_table("Book", |t| { + t.add_column("id", types::primary()); + t.inject_custom("meta json"); + }); + }) + .await?; + + assert_eq!(Version::NonPrisma, api.introspect_version().await?); + + Ok(()) +} diff --git a/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs b/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs index 6dca05e28adf..60f32556326b 100644 --- a/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs +++ b/introspection-engine/introspection-engine-tests/tests/rpc_calls/get_metadata_command_tests.rs @@ -3,7 +3,7 @@ use introspection_engine_tests::{test_api::*, BarrelMigrationExecutor}; use pretty_assertions::assert_eq; use test_macros::test_connector; -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn metadata_for_mysql_should_work(api: &TestApi) -> TestResult { setup(&api.barrel(), api.db_name()).await?; diff --git a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs index 8c924f7c8279..87f02f526d66 100644 --- a/migration-engine/migration-engine-tests/tests/native_types/mysql.rs +++ b/migration-engine/migration-engine-tests/tests/native_types/mysql.rs @@ -711,11 +711,11 @@ fn type_cast_is_unsupported_tidb(from_type: &str, to_type: &str) -> bool { } fn type_is_text(ty: &str) -> bool { - return ty.contains("Char") || ty.contains("Text") + return ty.contains("Char") || ty.contains("Text"); } fn type_is_binary(ty: &str) -> bool { - return ty.contains("Blob") || ty.contains("Binary") + return ty.contains("Blob") || ty.contains("Binary"); } fn filter_from_types(api: &TestApi, cases: Cases) -> Cow<'static, [Case]> { diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs index a3e2e0369989..1db2674c7abd 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/batch/in_selection_batching.rs @@ -35,27 +35,19 @@ mod isb { } // "batching of IN queries" should "work when having more than the specified amount of items" - #[connector_test] + // Exclude TiDB, TiDB does not guarantee the order of results returned when the `ORDER BY` + // clause is not specified + #[connector_test(exclude(TiDB))] async fn in_more_items(runner: Runner) -> TestResult<()> { create_test_data(&runner).await?; - if matches!(runner.connector(), ConnectorTag::TiDB(_)) { - insta::assert_snapshot!( - run_query!(&runner, indoc! { r#" - query { - findManyA(where: { id: { in: [5,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,1,2,3,4,5,6] }}) { id } - }"# }), - @r###"{"data":{"findManyA":[{"id":5},{"id":4},{"id":3},{"id":2},{"id":1}]}}"### - ); - } else { - insta::assert_snapshot!( - run_query!(&runner, indoc! { r#" - query { - findManyA(where: { id: { in: [5,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,1,2,3,4,5,6] }}) { id } - }"# }), - @r###"{"data":{"findManyA":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5}]}}"### - ); - } + insta::assert_snapshot!( + run_query!(&runner, indoc! { r#" + query { + findManyA(where: { id: { in: [5,4,3,2,1,1,1,2,3,4,5,6,7,6,5,4,3,2,1,2,3,4,5,6] }}) { id } + }"# }), + @r###"{"data":{"findManyA":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5}]}}"### + ); Ok(()) } @@ -92,7 +84,7 @@ mod isb { Ok(()) } - #[connector_test(exclude(MongoDb, TiDB))] + #[connector_test(exclude(MongoDb))] async fn order_by_aggregation_should_fail(runner: Runner) -> TestResult<()> { create_test_data(&runner).await?; From 719c4d44d32a57b0afc921803653331b0e230908 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 09:01:44 +0800 Subject: [PATCH 25/52] trigger testes --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 06f2c94dc48a..0c535141575a 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,6 @@ Notes: - in prisma/prisma repository, we do not run tests for `integration/` branches, it is much faster and also means that there is no risk of test failing (e.g. flaky tests, snapshots) that would stop the publishing process. - in prisma/prisma-engines tests must first pass, before publishing starts. So better keep an eye on them and restart them as needed. - ## Security If you have a security issue to report, please contact us at [security@prisma.io](mailto:security@prisma.io?subject=[GitHub]%20Prisma%202%20Security%20Report%20Engines) From 570a9f2b9df185b9a71b7be633eb3c2c13bb4054 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 09:02:49 +0800 Subject: [PATCH 26/52] Revert "trigger testes" This reverts commit 719c4d44d32a57b0afc921803653331b0e230908. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0c535141575a..06f2c94dc48a 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ Notes: - in prisma/prisma repository, we do not run tests for `integration/` branches, it is much faster and also means that there is no risk of test failing (e.g. flaky tests, snapshots) that would stop the publishing process. - in prisma/prisma-engines tests must first pass, before publishing starts. So better keep an eye on them and restart them as needed. + ## Security If you have a security issue to report, please contact us at [security@prisma.io](mailto:security@prisma.io?subject=[GitHub]%20Prisma%202%20Security%20Report%20Engines) From c71c91d8c13d3c0501d937af4e0213e97a3c0a07 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 11:35:48 +0800 Subject: [PATCH 27/52] fix: exclude tidb for relation with ignored referenced because of foreign keys --- .../mysql/ignore/relation_with_ignored_referenced_table.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/introspection-engine/introspection-engine-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql b/introspection-engine/introspection-engine-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql index b3a433a8027e..1f7bf4210b58 100644 --- a/introspection-engine/introspection-engine-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql +++ b/introspection-engine/introspection-engine-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql @@ -1,7 +1,7 @@ -- tags=mysql --- exclude=vitess +-- exclude=vitess,tidb --- Excluding Vitess because of foreign +-- Excluding Vitess/TiDB because of foreign -- keys. -- This table has no unique criteria, it will be ignored. From 4754ccf3b568e554946a880374cf535640282c6e Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 13:40:22 +0800 Subject: [PATCH 28/52] test: fix testcase in the mysql_describer_tests --- .../tests/describers/mysql_describer_tests.rs | 847 ++++++++++++++++-- 1 file changed, 768 insertions(+), 79 deletions(-) diff --git a/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs b/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs index 53841dec40f0..e879db2e69e8 100644 --- a/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs +++ b/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs @@ -2,7 +2,7 @@ use crate::test_api::*; use pretty_assertions::assert_eq; use sql_schema_describer::*; -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] fn views_can_be_described(api: TestApi) { let sql = r#" CREATE TABLE a (a_id int); @@ -24,7 +24,30 @@ fn views_can_be_described(api: TestApi) { assert_eq!(expected_sql, view.definition.unwrap()); } -#[test_connector(tags(Mysql))] +#[test_connector(tags(TiDB))] +fn views_can_be_described_on_tidb(api: TestApi) { + let sql = r#" + CREATE TABLE a (a_id int); + CREATE TABLE b (b_id int); + CREATE VIEW ab AS + SELECT a_id FROM a UNION ALL SELECT b_id FROM b; + "#; + api.raw_cmd(sql); + + let result = api.describe(); + let view = result.get_view("ab").expect("couldn't get ab view").to_owned(); + + let expected_sql = format!( + "SELECT `a_id` AS `a_id` FROM `{0}`.`a` UNION ALL SELECT `b_id` AS `b_id` FROM `{0}`.`b`", + api.db_name() + ); + + assert_eq!("ab", &view.name); + assert_eq!(expected_sql, view.definition.unwrap()); +} + +// Exclude TiDB, TiDB doesn't support procedures. +#[test_connector(tags(Mysql), exclude(TiDB))] fn procedures_can_be_described(api: TestApi) { let sql = format!( r#" @@ -41,7 +64,7 @@ fn procedures_can_be_described(api: TestApi) { assert_eq!(Some("SELECT 1 INTO res"), procedure.definition.as_deref()); } -#[test_connector(tags(Mysql), exclude(Mysql8, Mysql56, Mariadb))] +#[test_connector(tags(Mysql), exclude(Mysql8, Mysql56, Mariadb, TiDB))] fn all_mysql_column_types_must_work(api: TestApi) { let sql = r#" CREATE TABLE `User` ( @@ -2500,85 +2523,751 @@ fn all_mysql_8_column_types_must_work(api: TestApi) { api.expect_schema(expectation); } -#[test_connector(tags(Mysql))] -fn mysql_foreign_key_on_delete_must_be_handled(api: TestApi) { - // NB: We don't test the SET DEFAULT variety since it isn't supported on InnoDB and will - // just cause an error - let sql = format!( - "CREATE TABLE `{0}`.City (id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY); - CREATE TABLE `{0}`.User ( - id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, - city INTEGER, FOREIGN KEY(city) REFERENCES City (id) ON DELETE NO ACTION, - city_cascade INTEGER, FOREIGN KEY(city_cascade) REFERENCES City (id) ON DELETE CASCADE, - city_restrict INTEGER, FOREIGN KEY(city_restrict) REFERENCES City (id) ON DELETE RESTRICT, - city_set_null INTEGER, FOREIGN KEY(city_set_null) REFERENCES City (id) ON DELETE SET NULL - )", - api.db_name() - ); - api.raw_cmd(&sql); - - api.describe().assert_table("User", |t| { - t.assert_column("id", |id| id.assert_type_is_int()) - .assert_column("city", |c| c.assert_type_is_int()) - .assert_column("city_cascade", |c| c.assert_type_is_int()) - .assert_column("city_restrict", |c| c.assert_type_is_int()) - .assert_column("city_set_null", |c| c.assert_type_is_int()) - .assert_index_on_columns(&["city"], |idx| idx.assert_is_not_unique()) - .assert_index_on_columns(&["city_cascade"], |idx| idx.assert_is_not_unique()) - .assert_index_on_columns(&["city_restrict"], |idx| idx.assert_is_not_unique()) - .assert_index_on_columns(&["city_set_null"], |idx| idx.assert_is_not_unique()) - .assert_foreign_key_on_columns(&["city"], |fk| { - fk.assert_references("City", &["id"]) - .assert_on_delete(ForeignKeyAction::NoAction) - }) - .assert_foreign_key_on_columns(&["city_cascade"], |fk| { - fk.assert_references("City", &["id"]) - .assert_on_delete(ForeignKeyAction::Cascade) - }) - .assert_foreign_key_on_columns(&["city_restrict"], |fk| { - fk.assert_references("City", &["id"]) - .assert_on_delete(ForeignKeyAction::Restrict) - }) - .assert_foreign_key_on_columns(&["city_set_null"], |fk| { - fk.assert_references("City", &["id"]) - .assert_on_delete(ForeignKeyAction::SetNull) - }) - }); -} - -#[test_connector(tags(Mysql))] -fn mysql_join_table_unique_indexes_must_be_inferred(api: TestApi) { +#[test_connector(tags(TiDB))] +fn all_tidb_column_types_must_work(api: TestApi) { let sql = r#" - CREATE TABLE `Cat` ( - id INTEGER AUTO_INCREMENT PRIMARY KEY, - name TEXT - ); - - CREATE TABLE `Human` ( - id INTEGER AUTO_INCREMENT PRIMARY KEY, - name TEXT - ); - - CREATE TABLE `CatToHuman` ( - cat INTEGER REFERENCES `Cat`(id), - human INTEGER REFERENCES `Human`(id), - relationship TEXT + CREATE TABLE `User` ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + `int_col` int, + `smallint_col` smallint, + `tinyint4_col` tinyint(4), + `tinyint1_col` tinyint(1), + `mediumint_col` mediumint, + `bigint_col` bigint, + `decimal_col` decimal, + `numeric_col` numeric, + `float_col` float, + `double_col` double, + `date_col` date, + `time_col` time, + `datetime_col` datetime, + `timestamp_col` timestamp, + `year_col` year, + `char_col` char, + `varchar_col` varchar(255), + `text_col` text, + `tinytext_col` tinytext, + `mediumtext_col` mediumtext, + `longtext_col` longtext, + `enum_col` enum('a', 'b'), + `set_col` set('a', 'b'), + `binary_col` binary, + `varbinary_col` varbinary(255), + `blob_col` blob, + `tinyblob_col` tinyblob, + `mediumblob_col` mediumblob, + `longblob_col` longblob, + `json_col` json ); - - CREATE UNIQUE INDEX cat_and_human_index ON `CatToHuman`(cat, human); "#; api.raw_cmd(sql); - - api.describe().assert_table("CatToHuman", |t| { - t.assert_index_on_columns(&["cat", "human"], |idx| { - idx.assert_name("cat_and_human_index").assert_is_unique() - }) - }); -} - -// When multiple databases exist on a mysql instance, and they share names for foreign key -// constraints, introspecting one database should not yield constraints from the other. -#[test_connector(tags(Mysql))] + let expectation = expect![[r#" + SqlSchema { + namespaces: [], + tables: [ + Table { + namespace_id: NamespaceId( + 0, + ), + name: "User", + }, + ], + enums: [ + Enum { + namespace_id: NamespaceId( + 0, + ), + name: "User_enum_col", + }, + ], + enum_variants: [ + EnumVariant { + enum_id: EnumId( + 0, + ), + variant_name: "a", + }, + EnumVariant { + enum_id: EnumId( + 0, + ), + variant_name: "b", + }, + ], + columns: [ + ( + TableId( + 0, + ), + Column { + name: "id", + tpe: ColumnType { + full_data_type: "int(11)", + family: Int, + arity: Required, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: true, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "int_col", + tpe: ColumnType { + full_data_type: "int(11)", + family: Int, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "smallint_col", + tpe: ColumnType { + full_data_type: "smallint(6)", + family: Int, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "tinyint4_col", + tpe: ColumnType { + full_data_type: "tinyint(4)", + family: Int, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "tinyint1_col", + tpe: ColumnType { + full_data_type: "tinyint(1)", + family: Boolean, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "mediumint_col", + tpe: ColumnType { + full_data_type: "mediumint(9)", + family: Int, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "bigint_col", + tpe: ColumnType { + full_data_type: "bigint(20)", + family: BigInt, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "decimal_col", + tpe: ColumnType { + full_data_type: "decimal(10,0)", + family: Decimal, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "numeric_col", + tpe: ColumnType { + full_data_type: "decimal(10,0)", + family: Decimal, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "float_col", + tpe: ColumnType { + full_data_type: "float", + family: Float, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "double_col", + tpe: ColumnType { + full_data_type: "double", + family: Float, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "date_col", + tpe: ColumnType { + full_data_type: "date", + family: DateTime, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "time_col", + tpe: ColumnType { + full_data_type: "time", + family: DateTime, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "datetime_col", + tpe: ColumnType { + full_data_type: "datetime", + family: DateTime, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "timestamp_col", + tpe: ColumnType { + full_data_type: "timestamp", + family: DateTime, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "year_col", + tpe: ColumnType { + full_data_type: "year(4)", + family: Int, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "char_col", + tpe: ColumnType { + full_data_type: "char(1)", + family: String, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "varchar_col", + tpe: ColumnType { + full_data_type: "varchar(255)", + family: String, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "text_col", + tpe: ColumnType { + full_data_type: "text", + family: String, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "tinytext_col", + tpe: ColumnType { + full_data_type: "tinytext", + family: String, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "mediumtext_col", + tpe: ColumnType { + full_data_type: "mediumtext", + family: String, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "longtext_col", + tpe: ColumnType { + full_data_type: "longtext", + family: String, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "enum_col", + tpe: ColumnType { + full_data_type: "enum('a','b')", + family: Enum( + EnumId( + 0, + ), + ), + arity: Nullable, + native_type: None, + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "set_col", + tpe: ColumnType { + full_data_type: "set('a','b')", + family: String, + arity: Nullable, + native_type: None, + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "binary_col", + tpe: ColumnType { + full_data_type: "binary(1)", + family: Binary, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "varbinary_col", + tpe: ColumnType { + full_data_type: "varbinary(255)", + family: Binary, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "blob_col", + tpe: ColumnType { + full_data_type: "blob", + family: Binary, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "tinyblob_col", + tpe: ColumnType { + full_data_type: "tinyblob", + family: Binary, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "mediumblob_col", + tpe: ColumnType { + full_data_type: "mediumblob", + family: Binary, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "longblob_col", + tpe: ColumnType { + full_data_type: "longblob", + family: Binary, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ( + TableId( + 0, + ), + Column { + name: "json_col", + tpe: ColumnType { + full_data_type: "json", + family: Json, + arity: Nullable, + native_type: Some( + NativeTypeInstance(..), + ), + }, + default: None, + auto_increment: false, + }, + ), + ], + foreign_keys: [], + foreign_key_columns: [], + indexes: [ + Index { + table_id: TableId( + 0, + ), + index_name: "", + tpe: PrimaryKey, + }, + ], + index_columns: [ + IndexColumn { + index_id: IndexId( + 0, + ), + column_id: ColumnId( + 0, + ), + sort_order: Some( + Asc, + ), + length: None, + }, + ], + views: [], + procedures: [], + user_defined_types: [], + connector_data: , + } + "#]]; + api.expect_schema(expectation); +} + +#[test_connector(tags(Mysql))] +fn mysql_foreign_key_on_delete_must_be_handled(api: TestApi) { + // NB: We don't test the SET DEFAULT variety since it isn't supported on InnoDB and will + // just cause an error + let sql = format!( + "CREATE TABLE `{0}`.City (id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY); + CREATE TABLE `{0}`.User ( + id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, + city INTEGER, FOREIGN KEY(city) REFERENCES City (id) ON DELETE NO ACTION, + city_cascade INTEGER, FOREIGN KEY(city_cascade) REFERENCES City (id) ON DELETE CASCADE, + city_restrict INTEGER, FOREIGN KEY(city_restrict) REFERENCES City (id) ON DELETE RESTRICT, + city_set_null INTEGER, FOREIGN KEY(city_set_null) REFERENCES City (id) ON DELETE SET NULL + )", + api.db_name() + ); + api.raw_cmd(&sql); + + api.describe().assert_table("User", |t| { + t.assert_column("id", |id| id.assert_type_is_int()) + .assert_column("city", |c| c.assert_type_is_int()) + .assert_column("city_cascade", |c| c.assert_type_is_int()) + .assert_column("city_restrict", |c| c.assert_type_is_int()) + .assert_column("city_set_null", |c| c.assert_type_is_int()) + .assert_index_on_columns(&["city"], |idx| idx.assert_is_not_unique()) + .assert_index_on_columns(&["city_cascade"], |idx| idx.assert_is_not_unique()) + .assert_index_on_columns(&["city_restrict"], |idx| idx.assert_is_not_unique()) + .assert_index_on_columns(&["city_set_null"], |idx| idx.assert_is_not_unique()) + .assert_foreign_key_on_columns(&["city"], |fk| { + fk.assert_references("City", &["id"]) + .assert_on_delete(ForeignKeyAction::NoAction) + }) + .assert_foreign_key_on_columns(&["city_cascade"], |fk| { + fk.assert_references("City", &["id"]) + .assert_on_delete(ForeignKeyAction::Cascade) + }) + .assert_foreign_key_on_columns(&["city_restrict"], |fk| { + fk.assert_references("City", &["id"]) + .assert_on_delete(ForeignKeyAction::Restrict) + }) + .assert_foreign_key_on_columns(&["city_set_null"], |fk| { + fk.assert_references("City", &["id"]) + .assert_on_delete(ForeignKeyAction::SetNull) + }) + }); +} + +#[test_connector(tags(Mysql))] +fn mysql_join_table_unique_indexes_must_be_inferred(api: TestApi) { + let sql = r#" + CREATE TABLE `Cat` ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + name TEXT + ); + + CREATE TABLE `Human` ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + name TEXT + ); + + CREATE TABLE `CatToHuman` ( + cat INTEGER REFERENCES `Cat`(id), + human INTEGER REFERENCES `Human`(id), + relationship TEXT + ); + + CREATE UNIQUE INDEX cat_and_human_index ON `CatToHuman`(cat, human); + "#; + api.raw_cmd(sql); + + api.describe().assert_table("CatToHuman", |t| { + t.assert_index_on_columns(&["cat", "human"], |idx| { + idx.assert_name("cat_and_human_index").assert_is_unique() + }) + }); +} + +// When multiple databases exist on a mysql instance, and they share names for foreign key +// constraints, introspecting one database should not yield constraints from the other. +// Exclude TiDB, because of the foreign key. +#[test_connector(tags(Mysql), exclude(TiDB))] fn constraints_from_other_databases_should_not_be_introspected(api: TestApi) { api.block_on(api.database().raw_cmd("DROP DATABASE `other_schema`")) .ok(); @@ -3390,7 +4079,7 @@ fn function_expression_defaults_are_described_as_dbgenerated(api: TestApi) { api.expect_schema(expectation); } -#[test_connector(tags(Mysql), exclude(Mysql8))] +#[test_connector(tags(Mysql), exclude(Mysql8, TiDB))] fn dangling_foreign_keys_are_filtered_out(api: TestApi) { let setup = r#" SET FOREIGN_KEY_CHECKS=0; From 1f43ae196ea955ac73c49e428b264f61ca5ea7be Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 14:04:28 +0800 Subject: [PATCH 29/52] test: exclude tidb from mysql_foreign_key_on_delete_must_be_handled cause FK --- .../tests/describers/mysql_describer_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs b/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs index e879db2e69e8..36e85c97e874 100644 --- a/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs +++ b/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs @@ -3188,7 +3188,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { api.expect_schema(expectation); } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] fn mysql_foreign_key_on_delete_must_be_handled(api: TestApi) { // NB: We don't test the SET DEFAULT variety since it isn't supported on InnoDB and will // just cause an error From 4e39a8e7e5fb2b817d395892cb96c9adb2cc3b29 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 9 Dec 2022 14:09:17 +0800 Subject: [PATCH 30/52] test: `default` to `default_value_id` after merge base --- .../tests/describers/mysql_describer_tests.rs | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs b/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs index dc64559999bd..c08a4fd70142 100644 --- a/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs +++ b/libs/sql-schema-describer/tests/describers/mysql_describer_tests.rs @@ -2621,7 +2621,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: true, }, ), @@ -2639,7 +2639,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2657,7 +2657,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2675,7 +2675,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2693,7 +2693,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2711,7 +2711,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2729,7 +2729,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2747,7 +2747,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2765,7 +2765,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2783,7 +2783,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2801,7 +2801,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2819,7 +2819,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2837,7 +2837,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2855,7 +2855,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2873,7 +2873,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2891,7 +2891,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2909,7 +2909,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2927,7 +2927,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2945,7 +2945,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2963,7 +2963,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2981,7 +2981,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -2999,7 +2999,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3019,7 +3019,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { arity: Nullable, native_type: None, }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3035,7 +3035,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { arity: Nullable, native_type: None, }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3053,7 +3053,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3071,7 +3071,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3089,7 +3089,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3107,7 +3107,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3125,7 +3125,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3143,7 +3143,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), @@ -3161,12 +3161,13 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default: None, + default_value_id: None, auto_increment: false, }, ), ], foreign_keys: [], + default_values: [], foreign_key_columns: [], indexes: [ Index { From 32946d8d14c272f6e2c7daeac0967331dc70ebf7 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 18:06:20 +0800 Subject: [PATCH 31/52] fix: using TiDB 7.0 image and fix some new testes --- docker-compose.yml | 2 +- .../query-engine-tests/tests/new/metrics.rs | 1 + .../query-engine-tests/tests/queries/views.rs | 2 +- .../compound_fks_mixed_requiredness.rs | 2 +- .../src/connector_tag/tidb.rs | 5 +---- .../tests/identify_version/mod.rs | 19 +++++++++++++++++++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8e378e5c6c20..1691df2d590c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -181,7 +181,7 @@ services: tmpfs: /var/lib/mariadb tidb: - image: pingcap/tidb:v6.5.0-pre + image: pingcap/tidb:v7.0.0 restart: always platform: linux/x86_64 ports: diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/metrics.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/metrics.rs index 3b3971799074..b03d99cf901e 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/metrics.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/metrics.rs @@ -32,6 +32,7 @@ mod metrics { MongoDb(_) => assert_eq!(total_queries, 5), CockroachDb => assert_eq!(total_queries, 10), MySql(_) => assert_eq!(total_queries, 9), + TiDB => assert_eq!(total_queries, 9), Vitess(_) => assert_eq!(total_queries, 11), _ => assert_eq!(total_queries, 11), } diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/views.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/views.rs index cb4d567e3989..d89daa8d4b25 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/views.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/views.rs @@ -142,7 +142,7 @@ mod views { => { r#"CREATE VIEW "TestView" AS SELECT "TestModel".id, "TestModel"."firstName", "TestModel"."lastName", CONCAT("TestModel"."firstName", ' ', "TestModel"."lastName") as "fullName" From "TestModel""#.to_owned() } - ConnectorTag::MySql(_) | ConnectorTag::Vitess(_) + ConnectorTag::MySql(_) | ConnectorTag::Vitess(_) | ConnectorTag::TiDB(_) => { r#"CREATE VIEW TestView AS SELECT TestModel.*, CONCAT(TestModel.firstName, ' ', TestModel.lastName) AS "fullName" FROM TestModel"#.to_owned() }, diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs index eacad1ceb2ce..2ed763a1f123 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/writes/relations/compound_fks_mixed_requiredness.rs @@ -26,7 +26,7 @@ mod compound_fks { } // "A One to Many relation with mixed requiredness" should "be writable and readable" - #[connector_test(exclude(MySql(5.6), MongoDb, TiDB))] + #[connector_test(exclude(MySql(5.6), MongoDb))] async fn one2m_mix_required_writable_readable(runner: Runner) -> TestResult<()> { // Setup user insta::assert_snapshot!( diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 113b18aa685e..bd619bd4a63b 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -18,7 +18,7 @@ const CAPABILITIES: &[ConnectorCapability] = &[ ConnectorCapability::CompoundIds, ConnectorCapability::AnyId, ConnectorCapability::SqlQueryRaw, - // ConnectorCapability::NamedForeignKeys, + ConnectorCapability::NamedForeignKeys, ConnectorCapability::AdvancedJsonNullability, ConnectorCapability::IndexColumnLengthPrefixing, // ConnectorCapability::FullTextIndex, @@ -63,9 +63,6 @@ impl ConnectorTagInterface for TiDBConnectorTag { false } - fn relation_mode(&self) -> &'static str { - "prisma" - } } impl TiDBConnectorTag { diff --git a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs index b03150a4bef1..07034cc64b7f 100644 --- a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs @@ -340,3 +340,22 @@ async fn introspect_mssql_non_prisma_empty(api: &mut TestApi) -> TestResult { Ok(()) } + +// TiDB + +#[test_connector(tags(TiDB))] +async fn introspect_tidb_non_prisma(api: &mut TestApi) -> TestResult { + api.barrel() + .execute(|migration| { + migration.create_table("Book", |t| { + t.add_column("id", types::primary()); + t.inject_custom("meta json"); + }); + }) + .await?; + + assert_eq!(Version::NonPrisma, api.introspect_version().await?); + + Ok(()) +} + From 72328be57829071283198f928249974cbeca1bae Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 18:09:36 +0800 Subject: [PATCH 32/52] fix fmt --- .../query-tests-setup/src/connector_tag/tidb.rs | 1 - .../sql-introspection-tests/tests/identify_version/mod.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index bd619bd4a63b..970024590b79 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -62,7 +62,6 @@ impl ConnectorTagInterface for TiDBConnectorTag { fn is_versioned(&self) -> bool { false } - } impl TiDBConnectorTag { diff --git a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs index 07034cc64b7f..c1bea72fe4c2 100644 --- a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs @@ -358,4 +358,3 @@ async fn introspect_tidb_non_prisma(api: &mut TestApi) -> TestResult { Ok(()) } - From 10c9b4ded0672ce973bb247afdcd0277112aefa4 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 18:30:06 +0800 Subject: [PATCH 33/52] fix --- .../query-tests-setup/src/connector_tag/tidb.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 970024590b79..544358d3bae4 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -1,5 +1,6 @@ use super::*; use crate::SqlDatamodelRenderer; +use psl::datamodel_connector::ConnectorCapability; const CAPABILITIES: &[ConnectorCapability] = &[ ConnectorCapability::Enums, From 7e0eb8f892ddbfc420eb5ace681cbd3a17e8d83f Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 21:00:57 +0800 Subject: [PATCH 34/52] fix --- .../query-tests-setup/src/connector_tag/tidb.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 544358d3bae4..3c7f68957521 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -12,6 +12,7 @@ const CAPABILITIES: &[ConnectorCapability] = &[ ConnectorCapability::WritableAutoincField, ConnectorCapability::CreateSkipDuplicates, ConnectorCapability::UpdateableId, + ConnectorCapability::JsonFiltering, ConnectorCapability::JsonFilteringJsonPath, ConnectorCapability::JsonFilteringAlphanumeric, ConnectorCapability::CreateManyWriteableAutoIncId, @@ -22,6 +23,7 @@ const CAPABILITIES: &[ConnectorCapability] = &[ ConnectorCapability::NamedForeignKeys, ConnectorCapability::AdvancedJsonNullability, ConnectorCapability::IndexColumnLengthPrefixing, + ConnectorCapability::MultiSchema, // ConnectorCapability::FullTextIndex, // ConnectorCapability::FullTextSearchWithIndex, // ConnectorCapability::MultipleFullTextAttributesPerModel, @@ -74,10 +76,12 @@ impl TiDBConnectorTag { /// Returns all versions of this connector. pub fn all() -> Vec { - vec![Self::new()] + vec![Self { + capabilities: tidb_capabilities(), + }] } } fn tidb_capabilities() -> Vec { - (CAPABILITIES).to_vec() -} + CAPABILITIES.to_owned() +} \ No newline at end of file From d88be525eb6882fc1f5feb552dd6cc6f2fb194e9 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 21:04:44 +0800 Subject: [PATCH 35/52] fix fmt --- .../query-tests-setup/src/connector_tag/tidb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 3c7f68957521..faab97d64a3b 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -84,4 +84,4 @@ impl TiDBConnectorTag { fn tidb_capabilities() -> Vec { CAPABILITIES.to_owned() -} \ No newline at end of file +} From 31104733dde1988fc9a5c933b32a247970a02bab Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 21:21:44 +0800 Subject: [PATCH 36/52] fix fmt --- .../src/connector_tag/tidb.rs | 74 ++++++++----------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index faab97d64a3b..a4fea678fdeb 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -2,39 +2,35 @@ use super::*; use crate::SqlDatamodelRenderer; use psl::datamodel_connector::ConnectorCapability; -const CAPABILITIES: &[ConnectorCapability] = &[ - ConnectorCapability::Enums, - ConnectorCapability::EnumArrayPush, - ConnectorCapability::Json, - ConnectorCapability::AutoIncrementAllowedOnNonId, - ConnectorCapability::RelationFieldsInArbitraryOrder, - ConnectorCapability::CreateMany, - ConnectorCapability::WritableAutoincField, - ConnectorCapability::CreateSkipDuplicates, - ConnectorCapability::UpdateableId, - ConnectorCapability::JsonFiltering, - ConnectorCapability::JsonFilteringJsonPath, - ConnectorCapability::JsonFilteringAlphanumeric, - ConnectorCapability::CreateManyWriteableAutoIncId, - ConnectorCapability::AutoIncrement, - ConnectorCapability::CompoundIds, - ConnectorCapability::AnyId, - ConnectorCapability::SqlQueryRaw, - ConnectorCapability::NamedForeignKeys, - ConnectorCapability::AdvancedJsonNullability, - ConnectorCapability::IndexColumnLengthPrefixing, - ConnectorCapability::MultiSchema, - // ConnectorCapability::FullTextIndex, - // ConnectorCapability::FullTextSearchWithIndex, - // ConnectorCapability::MultipleFullTextAttributesPerModel, - ConnectorCapability::ImplicitManyToManyRelation, - ConnectorCapability::DecimalType, - ConnectorCapability::OrderByNullsFirstLast, - ConnectorCapability::SupportsTxIsolationReadUncommitted, - ConnectorCapability::SupportsTxIsolationReadCommitted, - ConnectorCapability::SupportsTxIsolationRepeatableRead, - // ConnectorCapability::SupportsTxIsolationSerializable, -]; +const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(ConnectorCapability::{ + Enums | + EnumArrayPush | + Json | + AutoIncrementAllowedOnNonId | + RelationFieldsInArbitraryOrder | + CreateMany | + WritableAutoincField | + CreateSkipDuplicates | + UpdateableId | + JsonFiltering | + JsonFilteringJsonPath | + JsonFilteringAlphanumeric | + CreateManyWriteableAutoIncId | + AutoIncrement | + CompoundIds | + AnyId | + SqlQueryRaw | + NamedForeignKeys | + AdvancedJsonNullability | + IndexColumnLengthPrefixing | + MultiSchema | + ImplicitManyToManyRelation | + DecimalType | + OrderByNullsFirstLast | + SupportsTxIsolationReadUncommitted | + SupportsTxIsolationReadCommitted | + SupportsTxIsolationRepeatableRead +}); #[derive(Debug, Default, Clone, PartialEq)] pub struct TiDBConnectorTag { @@ -69,19 +65,11 @@ impl ConnectorTagInterface for TiDBConnectorTag { impl TiDBConnectorTag { pub fn new() -> Self { - Self { - capabilities: tidb_capabilities(), - } + Self } /// Returns all versions of this connector. pub fn all() -> Vec { - vec![Self { - capabilities: tidb_capabilities(), - }] + vec![Self::new()] } } - -fn tidb_capabilities() -> Vec { - CAPABILITIES.to_owned() -} From 41805c481e287a23fc6d0b1925930b1368f6fedd Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 21:28:49 +0800 Subject: [PATCH 37/52] fix --- .../query-tests-setup/src/connector_tag/tidb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index a4fea678fdeb..adb988eee665 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -51,7 +51,7 @@ impl ConnectorTagInterface for TiDBConnectorTag { } fn capabilities(&self) -> &[ConnectorCapability] { - &self.capabilities + CAPABILITIES } fn as_parse_pair(&self) -> (String, Option) { From 88d6dc19d376e5263efbe3ba6781770d51a58095 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 21:32:30 +0800 Subject: [PATCH 38/52] fix --- .../query-tests-setup/src/connector_tag/tidb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index adb988eee665..5a7eb6e2cd70 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -51,7 +51,7 @@ impl ConnectorTagInterface for TiDBConnectorTag { } fn capabilities(&self) -> &[ConnectorCapability] { - CAPABILITIES + &CAPABILITIES } fn as_parse_pair(&self) -> (String, Option) { From 806389cc9d9cd2c9ade152c361779e4173cd00f7 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 21:43:28 +0800 Subject: [PATCH 39/52] fix --- .../query-tests-setup/src/connector_tag/tidb.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs index 5a7eb6e2cd70..d8f5ed82e324 100644 --- a/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs +++ b/query-engine/connector-test-kit-rs/query-tests-setup/src/connector_tag/tidb.rs @@ -33,9 +33,7 @@ const CAPABILITIES: ConnectorCapabilities = enumflags2::make_bitflags!(Connector }); #[derive(Debug, Default, Clone, PartialEq)] -pub struct TiDBConnectorTag { - capabilities: Vec, -} +pub struct TiDBConnectorTag {} impl ConnectorTagInterface for TiDBConnectorTag { fn datamodel_provider(&self) -> &'static str { @@ -50,8 +48,8 @@ impl ConnectorTagInterface for TiDBConnectorTag { format!("mysql://root@localhost:4000/{}", database) } - fn capabilities(&self) -> &[ConnectorCapability] { - &CAPABILITIES + fn capabilities(&self) -> ConnectorCapabilities { + CAPABILITIES } fn as_parse_pair(&self) -> (String, Option) { @@ -65,7 +63,7 @@ impl ConnectorTagInterface for TiDBConnectorTag { impl TiDBConnectorTag { pub fn new() -> Self { - Self + Self {} } /// Returns all versions of this connector. From 7b329a4db09966aee631291d0346a8c0c6ac050c Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 22:07:21 +0800 Subject: [PATCH 40/52] fix: using 'docker compose' --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6461dee3ee23..3b4bd9e47c16 100644 --- a/Makefile +++ b/Makefile @@ -162,7 +162,7 @@ dev-mariadb: start-mysql_mariadb cp $(CONFIG_PATH)/mariadb $(CONFIG_FILE) start-tidb: - docker-compose -f docker-compose.yml up -d --remove-orphans tidb + docker compose -f docker-compose.yml up -d --remove-orphans tidb dev-tidb: start-tidb cp $(CONFIG_PATH)/tidb $(CONFIG_FILE) From 10773b1e0102141a89f8d71090ac51e0a66c42a5 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Thu, 20 Apr 2023 22:25:23 +0800 Subject: [PATCH 41/52] fix: run occ test --- .../query-engine-tests/tests/new/occ.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs index d79f732c4ad1..242ff691d9ec 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/occ.rs @@ -112,7 +112,7 @@ mod occ { assert_eq!(booked_user_id, found_booked_user_id); } - #[connector_test(schema(occ_simple), exclude(MongoDB, CockroachDb, TiDB))] + #[connector_test(schema(occ_simple), exclude(MongoDB, CockroachDb))] async fn occ_update_many_test(runner: Runner) -> TestResult<()> { let runner = Arc::new(runner); @@ -127,7 +127,7 @@ mod occ { Ok(()) } - #[connector_test(schema(occ_simple), exclude(CockroachDb, TiDB))] + #[connector_test(schema(occ_simple), exclude(CockroachDb))] async fn occ_update_test(runner: Runner) -> TestResult<()> { let runner = Arc::new(runner); @@ -158,7 +158,7 @@ mod occ { Ok(()) } - #[connector_test(schema(occ_simple), exclude(TiDB))] + #[connector_test(schema(occ_simple))] async fn occ_delete_test(runner: Runner) -> TestResult<()> { let runner = Arc::new(runner); From df32a87144f8dcf6a1c25a485d101d66e0fb972d Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 21 Apr 2023 17:51:28 +0800 Subject: [PATCH 42/52] fix: fix new testes on query engine and schema engines --- .../tests/new/multi_schema.rs | 2 +- .../filters/field_reference/json_filter.rs | 2 +- .../tests/queries/filters/json_filters.rs | 2 +- .../tests/commenting_out/mysql.rs | 7 +++++-- .../tests/identify_version/mod.rs | 2 +- .../tests/named_constraints/mysql.rs | 6 ++++-- .../tests/relations/mysql.rs | 5 +++-- .../tests/tables/mod.rs | 3 ++- .../tests/tables/mysql.rs | 6 +++--- .../tests/views/mysql.rs | 21 ++++++++++++------- .../tests/existing_data/mod.rs | 3 ++- .../tests/migrations/mysql.rs | 6 ++---- 12 files changed, 39 insertions(+), 26 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/multi_schema.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/multi_schema.rs index 10d7c376b38e..ba779f18b630 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/multi_schema.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/new/multi_schema.rs @@ -1,6 +1,6 @@ use query_engine_tests::test_suite; -#[test_suite(capabilities(MultiSchema), exclude(Mysql))] +#[test_suite(capabilities(MultiSchema), exclude(Mysql, TiDB))] mod multi_schema { use query_engine_tests::*; diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/json_filter.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/json_filter.rs index b0ab7da42a7e..21c38385b06b 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/json_filter.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/json_filter.rs @@ -463,7 +463,7 @@ mod json_filter { fn json_path(runner: &Runner) -> &'static str { match runner.connector_version() { ConnectorVersion::Postgres(_) | ConnectorVersion::CockroachDb => r#"path: ["a", "b"]"#, - ConnectorVersion::MySql(_) => r#"path: "$.a.b""#, + ConnectorVersion::MySql(_) | ConnectorVersion::TiDB => r#"path: "$.a.b""#, x => unreachable!("JSON filtering is not supported on {:?}", x), } } diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs index 3b0605e1ab7d..ec981720db5f 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs @@ -224,7 +224,7 @@ mod json_filters { match runner.connector_version() { // MariaDB does not support finding arrays in arrays, unlike MySQL - ConnectorVersion::MySql(Some(MySqlVersion::MariaDb)) => { + ConnectorVersion::MySql(Some(MySqlVersion::MariaDb)) | ConnectorVersion::TiDB => { insta::assert_snapshot!( run_query!( runner, diff --git a/schema-engine/sql-introspection-tests/tests/commenting_out/mysql.rs b/schema-engine/sql-introspection-tests/tests/commenting_out/mysql.rs index 4b2e084b6056..26d29fd438cd 100644 --- a/schema-engine/sql-introspection-tests/tests/commenting_out/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/commenting_out/mysql.rs @@ -28,7 +28,8 @@ async fn a_table_without_required_uniques(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43267 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn a_table_without_uniques_should_ignore(api: &mut TestApi) -> TestResult { api.barrel() .execute(|migration| { @@ -104,7 +105,9 @@ async fn remapping_field_names_to_empty_mysql(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +// Exclude TiDB, cause alter table partition is unsupported. +// Related issue: https://github.com/pingcap/tidb/issues/42728 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn partition_table_gets_comment(api: &mut TestApi) -> TestResult { api.raw_cmd( r#" diff --git a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs index c1bea72fe4c2..b85db48f2f42 100644 --- a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs @@ -221,7 +221,7 @@ async fn introspect_mysql_non_prisma(api: &mut TestApi) -> TestResult { .execute(|migration| { migration.create_table("Book", |t| { t.add_column("id", types::primary()); - t.inject_custom("location point"); + t.inject_custom("location json"); }); }) .await?; diff --git a/schema-engine/sql-introspection-tests/tests/named_constraints/mysql.rs b/schema-engine/sql-introspection-tests/tests/named_constraints/mysql.rs index 2cc3b9a75003..6806e1430c33 100644 --- a/schema-engine/sql-introspection-tests/tests/named_constraints/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/named_constraints/mysql.rs @@ -4,7 +4,8 @@ use expect_test::expect; use sql_introspection_tests::test_api::*; use test_macros::test_connector; -#[test_connector(tags(Mysql), exclude(Vitess))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43267 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn introspecting_custom_fk_names_works(api: &mut TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -45,7 +46,8 @@ async fn introspecting_custom_fk_names_works(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43267 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn introspecting_default_fk_names_works(api: &mut TestApi) -> TestResult { api.barrel() .execute(move |migration| { diff --git a/schema-engine/sql-introspection-tests/tests/relations/mysql.rs b/schema-engine/sql-introspection-tests/tests/relations/mysql.rs index a0c33c01db49..7552db3addc9 100644 --- a/schema-engine/sql-introspection-tests/tests/relations/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/relations/mysql.rs @@ -534,7 +534,7 @@ async fn id_fields_with_foreign_key(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn one_to_one_req_relation_with_custom_fk_name(api: &mut TestApi) -> TestResult { api.barrel() .execute(move |migration| { @@ -642,7 +642,8 @@ async fn one_to_one_relation_on_a_singular_primary_key(api: &mut TestApi) -> Tes Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43267 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn multiple_foreign_key_constraints_are_taken_always_in_the_same_order(api: &mut TestApi) -> TestResult { let migration = indoc! {r#" CREATE TABLE A ( diff --git a/schema-engine/sql-introspection-tests/tests/tables/mod.rs b/schema-engine/sql-introspection-tests/tests/tables/mod.rs index 154aa213ce38..0853543a0f27 100644 --- a/schema-engine/sql-introspection-tests/tests/tables/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/tables/mod.rs @@ -724,7 +724,8 @@ async fn expression_indexes_should_be_ignored_on_sqlite(api: &mut TestApi) -> Te Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess))] +// Exclude TiDB,because tidb's table names are not case sensitive. +#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn casing_should_not_lead_to_mix_ups(api: &mut TestApi) -> TestResult { api.barrel() .execute(|migration| { diff --git a/schema-engine/sql-introspection-tests/tests/tables/mysql.rs b/schema-engine/sql-introspection-tests/tests/tables/mysql.rs index dd74d0c40ad9..d120c3a34dc9 100644 --- a/schema-engine/sql-introspection-tests/tests/tables/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/tables/mysql.rs @@ -219,7 +219,7 @@ async fn a_table_with_descending_unique(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), preview_features("fullTextIndex"), exclude(TiDB))] async fn a_table_with_fulltext_index(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE `A` ( @@ -248,7 +248,7 @@ async fn a_table_with_fulltext_index(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), preview_features("fullTextIndex"))] +#[test_connector(tags(Mysql), preview_features("fullTextIndex"), exclude(TiDB))] async fn a_table_with_fulltext_index_with_custom_name(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE `A` ( @@ -277,7 +277,7 @@ async fn a_table_with_fulltext_index_with_custom_name(api: &mut TestApi) -> Test Ok(()) } -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn a_table_with_fulltext_index_without_preview_flag(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE `A` ( diff --git a/schema-engine/sql-introspection-tests/tests/views/mysql.rs b/schema-engine/sql-introspection-tests/tests/views/mysql.rs index e588c88e797b..f36293c7ecea 100644 --- a/schema-engine/sql-introspection-tests/tests/views/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/views/mysql.rs @@ -1,7 +1,8 @@ use indoc::indoc; use sql_introspection_tests::test_api::*; -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB), preview_features("views"))] async fn simple_view_from_one_table(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE A ( @@ -72,7 +73,8 @@ async fn simple_view_from_one_table(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess, Mariadb), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43264 +#[test_connector(tags(Mysql), exclude(Vitess, Mariadb), preview_features("views"), exclude(TiDB))] async fn simple_view_from_two_tables(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -150,7 +152,8 @@ async fn simple_view_from_two_tables(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB), preview_features("views"))] async fn re_intro_keeps_view_uniques(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -198,7 +201,8 @@ async fn re_intro_keeps_view_uniques(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 +#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"), exclude(TiDB))] async fn re_intro_keeps_id(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -246,7 +250,8 @@ async fn re_intro_keeps_id(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 +#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"), exclude(TiDB))] async fn re_intro_keeps_compound_unique(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -308,7 +313,8 @@ async fn re_intro_keeps_compound_unique(api: &mut TestApi) -> TestResult { Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 +#[test_connector(tags(Mysql), exclude(Vitess, TiDB), preview_features("views"))] async fn re_intro_keeps_view_to_view_relations(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE VIEW A AS SELECT 1 AS id; @@ -348,7 +354,8 @@ async fn re_intro_keeps_view_to_view_relations(api: &mut TestApi) -> TestResult Ok(()) } -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"))] +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 +#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"), exclude(TiDB))] async fn defaults_are_introspected(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE A (id INT PRIMARY KEY, val INT DEFAULT 2); diff --git a/schema-engine/sql-migration-tests/tests/existing_data/mod.rs b/schema-engine/sql-migration-tests/tests/existing_data/mod.rs index 461214dd62ae..ae6133f5d2c7 100644 --- a/schema-engine/sql-migration-tests/tests/existing_data/mod.rs +++ b/schema-engine/sql-migration-tests/tests/existing_data/mod.rs @@ -784,8 +784,9 @@ fn set_default_current_timestamp_on_existing_column_works(api: TestApi) { // Excluding Vitess because schema changes being asynchronous messes with our assertions // (dump_table). +// Exclude TiDB, unsupported drop primary key when the table is using clustered index. // exclude: there is a cockroach-specific test. It's unexecutable there. -#[test_connector(exclude(CockroachDb, Vitess))] +#[test_connector(exclude(CockroachDb, Vitess, TiDB))] fn primary_key_migrations_do_not_cause_data_loss(api: TestApi) { let dm1 = r#" model Dog { diff --git a/schema-engine/sql-migration-tests/tests/migrations/mysql.rs b/schema-engine/sql-migration-tests/tests/migrations/mysql.rs index 813a8206666d..d8332af437b5 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/mysql.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/mysql.rs @@ -221,13 +221,13 @@ fn native_type_columns_can_be_created(api: TestApi) { "bits", "Bytes", "Bit(10)", - if api.is_tidb() { "bit(10) unsigned" } else { "bit(10)" }, + "bit(10)", ), ( "bit", "Boolean", "Bit(1)", - if api.is_tidb() { "bit(1) unsigned" } else { "bit(1)" }, + "bit(1)", ), ("chars", "String", "Char(10)", "char(10)"), ("varchars", "String", "VarChar(500)", "varchar(500)"), @@ -256,8 +256,6 @@ fn native_type_columns_can_be_created(api: TestApi) { "Year", if api.is_mysql_8() { "year" - } else if api.is_tidb() { - "year(4) unsigned" } else { "year(4)" }, From c89302c61efb550d3e8692da4b99b827f5077e72 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Fri, 21 Apr 2023 17:54:19 +0800 Subject: [PATCH 43/52] fix fmt --- .../tests/migrations/mysql.rs | 25 +++---------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/schema-engine/sql-migration-tests/tests/migrations/mysql.rs b/schema-engine/sql-migration-tests/tests/migrations/mysql.rs index d8332af437b5..d9d7c9c3d3f9 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/mysql.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/mysql.rs @@ -217,18 +217,8 @@ fn native_type_columns_can_be_created(api: TestApi) { ("decimal", "Decimal", "Decimal(5, 3)", "decimal(5,3)"), ("float", "Float", "Float", "float"), ("double", "Float", "Double", "double"), - ( - "bits", - "Bytes", - "Bit(10)", - "bit(10)", - ), - ( - "bit", - "Boolean", - "Bit(1)", - "bit(1)", - ), + ("bits", "Bytes", "Bit(10)", "bit(10)"), + ("bit", "Boolean", "Bit(1)", "bit(1)"), ("chars", "String", "Char(10)", "char(10)"), ("varchars", "String", "VarChar(500)", "varchar(500)"), ("binary", "Bytes", "Binary(230)", "binary(230)"), @@ -250,16 +240,7 @@ fn native_type_columns_can_be_created(api: TestApi) { "Timestamp(3)", "timestamp(3)", ), - ( - "year", - "Int", - "Year", - if api.is_mysql_8() { - "year" - } else { - "year(4)" - }, - ), + ("year", "Int", "Year", if api.is_mysql_8() { "year" } else { "year(4)" }), ]; let mut dm = r#" From beba669c09268968752efa4f65ab9987186616cf Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sat, 22 Apr 2023 00:45:31 +0800 Subject: [PATCH 44/52] fix: remove exclude for foreign keys testes --- .../tests/identify_version/mod.rs | 2 +- ...relation_with_ignored_referenced_table.sql | 4 +- .../tests/views/mysql.rs | 8 +- .../tests/migrations/foreign_keys.rs | 3 +- .../tests/migrations/id.rs | 6 +- .../tests/migrations/indexes.rs | 2 +- .../tests/migrations/mysql.rs | 4 +- .../tests/migrations/relations.rs | 26 +++---- .../tests/describers/mysql_describer_tests.rs | 76 ++++++++++--------- 9 files changed, 69 insertions(+), 62 deletions(-) diff --git a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs index b85db48f2f42..c1bea72fe4c2 100644 --- a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs @@ -221,7 +221,7 @@ async fn introspect_mysql_non_prisma(api: &mut TestApi) -> TestResult { .execute(|migration| { migration.create_table("Book", |t| { t.add_column("id", types::primary()); - t.inject_custom("location json"); + t.inject_custom("location point"); }); }) .await?; diff --git a/schema-engine/sql-introspection-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql b/schema-engine/sql-introspection-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql index 549eb51efd6b..6d724c9c88b1 100644 --- a/schema-engine/sql-introspection-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql +++ b/schema-engine/sql-introspection-tests/tests/simple/mysql/ignore/relation_with_ignored_referenced_table.sql @@ -1,7 +1,7 @@ -- tags=mysql --- exclude=vitess,tidb +-- exclude=vitess --- Excluding Vitess/TiDB because of foreign +-- Excluding Vitess because of foreign -- keys. -- This table has no unique criteria, it will be ignored. diff --git a/schema-engine/sql-introspection-tests/tests/views/mysql.rs b/schema-engine/sql-introspection-tests/tests/views/mysql.rs index f36293c7ecea..c77a5963fd9c 100644 --- a/schema-engine/sql-introspection-tests/tests/views/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/views/mysql.rs @@ -74,7 +74,7 @@ async fn simple_view_from_one_table(api: &mut TestApi) -> TestResult { } // Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43264 -#[test_connector(tags(Mysql), exclude(Vitess, Mariadb), preview_features("views"), exclude(TiDB))] +#[test_connector(tags(Mysql), exclude(Vitess, Mariadb, TiDB), preview_features("views"))] async fn simple_view_from_two_tables(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -202,7 +202,7 @@ async fn re_intro_keeps_view_uniques(api: &mut TestApi) -> TestResult { } // Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"), exclude(TiDB))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB), preview_features("views"))] async fn re_intro_keeps_id(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -251,7 +251,7 @@ async fn re_intro_keeps_id(api: &mut TestApi) -> TestResult { } // Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"), exclude(TiDB))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB), preview_features("views"))] async fn re_intro_keeps_compound_unique(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE User ( @@ -355,7 +355,7 @@ async fn re_intro_keeps_view_to_view_relations(api: &mut TestApi) -> TestResult } // Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43265 -#[test_connector(tags(Mysql), exclude(Vitess), preview_features("views"), exclude(TiDB))] +#[test_connector(tags(Mysql), exclude(Vitess, TiDB), preview_features("views"))] async fn defaults_are_introspected(api: &mut TestApi) -> TestResult { let setup = indoc! {r#" CREATE TABLE A (id INT PRIMARY KEY, val INT DEFAULT 2); diff --git a/schema-engine/sql-migration-tests/tests/migrations/foreign_keys.rs b/schema-engine/sql-migration-tests/tests/migrations/foreign_keys.rs index 5b0113cf4cf7..4b50ed193a41 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/foreign_keys.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/foreign_keys.rs @@ -284,8 +284,7 @@ fn changing_a_foreign_key_constrained_column_from_nullable_to_required_and_back_ api.schema_push_w_datasource(dm).send().assert_green(); } -// Ignore TiDB, unsupported drop primary key when the table's pkIsHandle is true, -// which means we can't drop primary key when the table is using clustered index. +// Exclude TiDB, unsupported drop primary key when the table is using clustered index. #[test_connector(exclude(CockroachDb, TiDB))] fn changing_all_referenced_columns_of_foreign_key_works(api: TestApi) { let dm1 = r#" diff --git a/schema-engine/sql-migration-tests/tests/migrations/id.rs b/schema-engine/sql-migration-tests/tests/migrations/id.rs index dbacfdf6373a..21e9c4c2829c 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/id.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/id.rs @@ -107,7 +107,7 @@ fn length_prefixed_compound_primary_key(api: TestApi) { }); } -// Ignoring TiDB, unsupported drop primary key when the table's pkIsHandle is true. +// Ignoring TiDB, unsupported drop primary key when the table is using clustered index. // TODO: ignore because not possible on cockroachdb. We would need a multi-step process there. #[test_connector(exclude(Vitess, CockroachDb, TiDB))] fn changing_the_type_of_an_id_field_must_work(api: TestApi) { @@ -185,8 +185,8 @@ fn models_with_an_autoincrement_field_as_part_of_a_multi_field_id_can_be_created } // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. -// Ignoring TiDB, we can't set auto_increment for an existing id field to auto-incrementing in TiDB. -#[test_connector(exclude(Sqlite, CockroachDb, TiDB))] +// Ignoring TiDB, we can't set auto_increment for an existing field. +#[test_connector(exclude(Sqlite, CockroachDb))] fn making_an_existing_id_field_autoincrement_works(api: TestApi) { use quaint::ast::{Insert, Select}; diff --git a/schema-engine/sql-migration-tests/tests/migrations/indexes.rs b/schema-engine/sql-migration-tests/tests/migrations/indexes.rs index 7198ec0c048e..00b5fc9c7fc3 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/indexes.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/indexes.rs @@ -108,7 +108,7 @@ fn unique_directive_on_required_one_to_one_relation_creates_one_index(api: TestA .assert_table("Cat", |table| table.assert_indexes_count(1)); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn one_to_many_self_relations_do_not_create_a_unique_index(api: TestApi) { let dm = r#" model Location { diff --git a/schema-engine/sql-migration-tests/tests/migrations/mysql.rs b/schema-engine/sql-migration-tests/tests/migrations/mysql.rs index d9d7c9c3d3f9..9bcd1f79d489 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/mysql.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/mysql.rs @@ -6,7 +6,7 @@ use std::fmt::Write as _; // We need to test this specifically for mysql, because foreign keys are indexes, and they are // inferred as both foreign key and index by the sql-schema-describer. We do not want to // create/delete a second index. -#[test_connector(tags(Mysql), exclude(Vitess, TiDB))] +#[test_connector(tags(Mysql), exclude(Vitess))] fn indexes_on_foreign_key_fields_are_not_created_twice(api: TestApi) { let schema = r#" model Human { @@ -491,7 +491,7 @@ fn dropping_m2m_relation_from_datamodel_works() { expected.assert_eq(&diff); } -#[cfg_attr(not(target_os = "windows"), test_connector(tags(Mysql), exclude(Vitess, TiDB)))] +#[cfg_attr(not(target_os = "windows"), test_connector(tags(Mysql), exclude(Vitess)))] fn alter_constraint_name(mut api: TestApi) { let plain_dm = api.datamodel_with_provider( r#" diff --git a/schema-engine/sql-migration-tests/tests/migrations/relations.rs b/schema-engine/sql-migration-tests/tests/migrations/relations.rs index ca4b36d38d32..d58e9efd8590 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/relations.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/relations.rs @@ -111,7 +111,7 @@ fn adding_an_inline_relation_must_result_in_a_foreign_key_in_the_model_table(api }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn specifying_a_db_name_for_an_inline_relation_must_work(api: TestApi) { let dm1 = r#" model A { @@ -261,7 +261,7 @@ fn removing_an_inline_relation_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn compound_foreign_keys_should_work_in_correct_order(api: TestApi) { let dm1 = r#" model A { @@ -406,7 +406,7 @@ fn relations_can_reference_arbitrary_unique_fields_with_maps(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn relations_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -437,7 +437,7 @@ fn relations_can_reference_multiple_fields(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn a_relation_with_mappings_on_both_sides_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -470,7 +470,7 @@ fn a_relation_with_mappings_on_both_sides_can_reference_multiple_fields(api: Tes }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn relations_with_mappings_on_referenced_side_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -502,7 +502,7 @@ fn relations_with_mappings_on_referenced_side_can_reference_multiple_fields(api: }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn relations_with_mappings_on_referencing_side_can_reference_multiple_fields(api: TestApi) { let dm = r#" model User { @@ -624,7 +624,7 @@ fn on_delete_restrict_should_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn on_update_referential_actions_should_work(api: TestApi) { let actions = &[ (ReferentialAction::NoAction, ForeignKeyAction::NoAction), @@ -787,7 +787,7 @@ fn on_delete_optional_default_action(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn on_delete_compound_optional_optional_default_action(api: TestApi) { let dm = r#" model A { @@ -817,7 +817,7 @@ fn on_delete_compound_optional_optional_default_action(api: TestApi) { }); } -#[test_connector(exclude(Mssql, Vitess, TiDB))] +#[test_connector(exclude(Mssql, Vitess))] fn on_delete_compound_required_optional_default_action_with_restrict(api: TestApi) { let dm = r#" model A { @@ -927,7 +927,7 @@ fn on_update_required_default_action(api: TestApi) { }); } -#[test_connector(exclude(Vitess, CockroachDb, TiDB))] +#[test_connector(exclude(Vitess, CockroachDb))] fn adding_mutual_references_on_existing_tables_works(api: TestApi) { let dm1 = r#" model A { @@ -1067,7 +1067,7 @@ fn removing_a_relation_field_must_work(api: TestApi) { .assert_table("User", |table| table.assert_does_not_have_column("address_name")); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn references_to_models_with_compound_primary_keys_must_work(api: TestApi) { let dm = r#" model User { @@ -1101,7 +1101,7 @@ fn references_to_models_with_compound_primary_keys_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn join_tables_between_models_with_compound_primary_keys_must_work(api: TestApi) { let dm = r#" model Human { @@ -1161,7 +1161,7 @@ fn join_tables_between_models_with_compound_primary_keys_must_work(api: TestApi) }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn join_tables_between_models_with_mapped_compound_primary_keys_must_work(api: TestApi) { let dm = r#" model Human { diff --git a/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs b/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs index 4c817a297706..1e3ef67bd562 100644 --- a/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs +++ b/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs @@ -2602,6 +2602,10 @@ fn all_tidb_column_types_must_work(api: TestApi) { 0, ), name: "User", + properties: BitFlags { + bits: 0b0, + }, + description: None, }, ], enums: [ @@ -2610,6 +2614,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { 0, ), name: "User_enum_col", + description: None, }, ], enum_variants: [ @@ -2626,7 +2631,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { variant_name: "b", }, ], - columns: [ + table_columns: [ ( TableId( 0, @@ -2641,8 +2646,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: true, + description: None, }, ), ( @@ -2659,8 +2664,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2677,8 +2682,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2695,8 +2700,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2713,8 +2718,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2731,8 +2736,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2749,8 +2754,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2767,8 +2772,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2785,8 +2790,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2803,8 +2808,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2821,8 +2826,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2839,8 +2844,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2857,8 +2862,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2875,8 +2880,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2893,8 +2898,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2911,8 +2916,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2929,8 +2934,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2947,8 +2952,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2965,8 +2970,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -2983,8 +2988,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3001,8 +3006,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3019,8 +3024,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3039,8 +3044,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { arity: Nullable, native_type: None, }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3055,8 +3060,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { arity: Nullable, native_type: None, }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3073,8 +3078,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3091,8 +3096,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3109,8 +3114,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3127,8 +3132,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3145,8 +3150,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3163,8 +3168,8 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ( @@ -3181,13 +3186,14 @@ fn all_tidb_column_types_must_work(api: TestApi) { NativeTypeInstance(..), ), }, - default_value_id: None, auto_increment: false, + description: None, }, ), ], foreign_keys: [], - default_values: [], + table_default_values: [], + view_default_values: [], foreign_key_columns: [], indexes: [ Index { @@ -3203,7 +3209,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { index_id: IndexId( 0, ), - column_id: ColumnId( + column_id: TableColumnId( 0, ), sort_order: Some( @@ -3212,7 +3218,9 @@ fn all_tidb_column_types_must_work(api: TestApi) { length: None, }, ], + check_constraints: [], views: [], + view_columns: [], procedures: [], user_defined_types: [], connector_data: , From 65e2cd3ea3a551fdbe2cd94c02d7de33fef2cfb7 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sat, 22 Apr 2023 00:59:11 +0800 Subject: [PATCH 45/52] fix --- .../sql-introspection-tests/tests/identify_version/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs index c1bea72fe4c2..c552e7b5a7af 100644 --- a/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/identify_version/mod.rs @@ -215,7 +215,7 @@ async fn introspect_postgres_prisma2(api: &mut TestApi) -> TestResult { //Mysql -#[test_connector(tags(Mysql))] +#[test_connector(tags(Mysql), exclude(TiDB))] async fn introspect_mysql_non_prisma(api: &mut TestApi) -> TestResult { api.barrel() .execute(|migration| { From e3e00308524e5837057dd556ae2dc3aff7b920b5 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Sat, 22 Apr 2023 22:56:19 +0800 Subject: [PATCH 46/52] fix: fix having_filter test and remove exclude for fk test --- .../tests/queries/filters/field_reference/having_filter.rs | 2 +- .../sql-introspection-tests/tests/relations/mysql.rs | 1 + schema-engine/sql-migration-tests/tests/migrations/sql.rs | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/having_filter.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/having_filter.rs index a38a4d2b665f..7ca05fccf587 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/having_filter.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/field_reference/having_filter.rs @@ -39,7 +39,7 @@ mod having_filter { string2 } }"#, - MongoDb(_) => vec![ + MongoDb(_) | TiDB => vec![ r#"{"data":{"groupByTestModel":[{"string":"group1","string2":"group1"},{"string":"group2","string2":"group2"}]}}"#, r#"{"data":{"groupByTestModel":[{"string":"group2","string2":"group2"},{"string":"group1","string2":"group1"}]}}"# ], diff --git a/schema-engine/sql-introspection-tests/tests/relations/mysql.rs b/schema-engine/sql-introspection-tests/tests/relations/mysql.rs index 7552db3addc9..b3ad049d3533 100644 --- a/schema-engine/sql-introspection-tests/tests/relations/mysql.rs +++ b/schema-engine/sql-introspection-tests/tests/relations/mysql.rs @@ -534,6 +534,7 @@ async fn id_fields_with_foreign_key(api: &mut TestApi) -> TestResult { Ok(()) } +// Exclude TiDB, cause: https://github.com/pingcap/tidb/issues/43267 #[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn one_to_one_req_relation_with_custom_fk_name(api: &mut TestApi) -> TestResult { api.barrel() diff --git a/schema-engine/sql-migration-tests/tests/migrations/sql.rs b/schema-engine/sql-migration-tests/tests/migrations/sql.rs index 1ff69f9155a8..9e270c987adc 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/sql.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/sql.rs @@ -71,7 +71,7 @@ fn creating_tables_without_primary_key_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn relations_to_models_without_a_primary_key_work(api: TestApi) { let dm = r#" model Pair { @@ -282,7 +282,7 @@ fn id_as_part_of_relation_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn multi_field_id_as_part_of_relation_must_work(api: TestApi) { let dm = r##" model Cat { @@ -314,7 +314,7 @@ fn multi_field_id_as_part_of_relation_must_work(api: TestApi) { }); } -#[test_connector(exclude(Vitess, TiDB))] +#[test_connector(exclude(Vitess))] fn remapped_multi_field_id_as_part_of_relation_must_work(api: TestApi) { let dm = r##" model Cat { From caf2b09169afb180c2c835041c1d969896bbfca8 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 24 Apr 2023 12:03:23 +0800 Subject: [PATCH 47/52] fix: fix adding_mutual_references_on_existing_tables_works test and exclude making_an_existing_id_field_autoincrement_works test --- .../tests/migrations/id.rs | 4 +- .../tests/migrations/relations.rs | 7 +-- .../tests/migrations/relations/tidb.rs | 43 +++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 schema-engine/sql-migration-tests/tests/migrations/relations/tidb.rs diff --git a/schema-engine/sql-migration-tests/tests/migrations/id.rs b/schema-engine/sql-migration-tests/tests/migrations/id.rs index 21e9c4c2829c..0b0e01087eb3 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/id.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/id.rs @@ -185,8 +185,8 @@ fn models_with_an_autoincrement_field_as_part_of_a_multi_field_id_can_be_created } // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. -// Ignoring TiDB, we can't set auto_increment for an existing field. -#[test_connector(exclude(Sqlite, CockroachDb))] +// Exclude TiDB, cannot set auto_increment through alter table, doc: https://docs.pingcap.com/tidb/dev/auto-increment#restrictions +#[test_connector(exclude(Sqlite, CockroachDb, TiDB))] fn making_an_existing_id_field_autoincrement_works(api: TestApi) { use quaint::ast::{Insert, Select}; diff --git a/schema-engine/sql-migration-tests/tests/migrations/relations.rs b/schema-engine/sql-migration-tests/tests/migrations/relations.rs index d58e9efd8590..8c8aa4075d51 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/relations.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/relations.rs @@ -1,4 +1,5 @@ mod cockroachdb; +mod tidb; mod vitess; use psl::parser_database::ReferentialAction; @@ -927,7 +928,7 @@ fn on_update_required_default_action(api: TestApi) { }); } -#[test_connector(exclude(Vitess, CockroachDb))] +#[test_connector(exclude(Vitess, CockroachDb, TiDB))] fn adding_mutual_references_on_existing_tables_works(api: TestApi) { let dm1 = r#" model A { @@ -943,7 +944,7 @@ fn adding_mutual_references_on_existing_tables_works(api: TestApi) { let dm2 = r#" model A { - id Int + id Int @id name String @unique b_email String brel B @relation("AtoB", fields: [b_email], references: [email], onDelete: NoAction, onUpdate: NoAction) @@ -951,7 +952,7 @@ fn adding_mutual_references_on_existing_tables_works(api: TestApi) { } model B { - id Int + id Int @id email String @unique a_name String arel A @relation("BtoA", fields: [a_name], references: [name], onDelete: NoAction, onUpdate: NoAction) diff --git a/schema-engine/sql-migration-tests/tests/migrations/relations/tidb.rs b/schema-engine/sql-migration-tests/tests/migrations/relations/tidb.rs new file mode 100644 index 000000000000..ccb6babed3a0 --- /dev/null +++ b/schema-engine/sql-migration-tests/tests/migrations/relations/tidb.rs @@ -0,0 +1,43 @@ +use sql_migration_tests::test_api::*; + +// TiDB unsupported drop primary key when the table is using clustered index. +#[test_connector(tags(TiDB))] +fn adding_mutual_references_on_existing_tables_works(api: TestApi) { + let dm1 = r#" + model A { + id Int @id + } + + model B { + id Int @id + } + "#; + + api.schema_push_w_datasource(dm1).send().assert_green(); + + let dm2 = r#" + model A { + id Int @id + name String @unique + b_email String + brel B @relation("AtoB", fields: [b_email], references: [email], onDelete: NoAction, onUpdate: NoAction) + b B[] @relation("BtoA") + } + + model B { + id Int @id + email String @unique + a_name String + arel A @relation("BtoA", fields: [a_name], references: [name], onDelete: NoAction, onUpdate: NoAction) + a A[] @relation("AtoB") + } + "#; + + let res = api.schema_push_w_datasource(dm2).force(true).send(); + + if api.is_sqlite() { + res.assert_green(); + } else { + res.assert_warnings(&["A unique constraint covering the columns `[name]` on the table `A` will be added. If there are existing duplicate values, this will fail.".into(), "A unique constraint covering the columns `[email]` on the table `B` will be added. If there are existing duplicate values, this will fail.".into()]); + }; +} From ff26b962a19f092af959f350f33ef2a91fb0e49c Mon Sep 17 00:00:00 2001 From: Mini256 Date: Mon, 24 Apr 2023 13:26:39 +0800 Subject: [PATCH 48/52] try to use single threaded to run schema engine test --- .github/workflows/schema-engine.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/schema-engine.yml b/.github/workflows/schema-engine.yml index 04d4a9a779ea..1e21842b8ea7 100644 --- a/.github/workflows/schema-engine.yml +++ b/.github/workflows/schema-engine.yml @@ -76,6 +76,7 @@ jobs: url: "mysql://root:prisma@localhost:3308" - name: tidb url: "mysql://root@localhost:4000" + single_threaded: true - name: postgres9 url: "postgresql://postgres:prisma@localhost:5431" - name: postgres10 From 25fdeb1770039bf6faa103112e1738ec2a149b14 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Wed, 26 Apr 2023 14:53:01 +0800 Subject: [PATCH 49/52] fix: skip get_lock for TiDB and refine some testes --- .github/workflows/schema-engine.yml | 1 - .../tests/queries/filters/json_filters.rs | 2 +- .../sql-schema-connector/src/flavour/mysql.rs | 23 +++++- .../tests/tables/mod.rs | 2 +- .../tests/migrations/id.rs | 3 +- .../tests/migrations/relations.rs | 4 +- .../tests/describers/mysql_describer_tests.rs | 81 ++++++++++--------- 7 files changed, 68 insertions(+), 48 deletions(-) diff --git a/.github/workflows/schema-engine.yml b/.github/workflows/schema-engine.yml index 1e21842b8ea7..04d4a9a779ea 100644 --- a/.github/workflows/schema-engine.yml +++ b/.github/workflows/schema-engine.yml @@ -76,7 +76,6 @@ jobs: url: "mysql://root:prisma@localhost:3308" - name: tidb url: "mysql://root@localhost:4000" - single_threaded: true - name: postgres9 url: "postgresql://postgres:prisma@localhost:5431" - name: postgres10 diff --git a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs index ec981720db5f..64d8d50d967b 100644 --- a/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs +++ b/query-engine/connector-test-kit-rs/query-engine-tests/tests/queries/filters/json_filters.rs @@ -223,7 +223,7 @@ mod json_filters { ); match runner.connector_version() { - // MariaDB does not support finding arrays in arrays, unlike MySQL + // MariaDB / TiDB does not support finding arrays in arrays, unlike MySQL ConnectorVersion::MySql(Some(MySqlVersion::MariaDb)) | ConnectorVersion::TiDB => { insta::assert_snapshot!( run_query!( diff --git a/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs b/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs index 73c5e60d88e7..4e859b106d6e 100644 --- a/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs +++ b/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs @@ -51,6 +51,10 @@ impl MysqlFlavour { self.circumstances().contains(Circumstances::IsMysql56) } + pub(crate) fn is_tidb(&self) -> bool { + self.circumstances().contains(Circumstances::IsTiDB) + } + pub(crate) fn lower_cases_table_names(&self) -> bool { self.circumstances().contains(Circumstances::LowerCasesTableNames) } @@ -69,7 +73,7 @@ impl MysqlFlavour { impl SqlFlavour for MysqlFlavour { fn acquire_lock(&mut self) -> BoxFuture<'_, ConnectorResult<()>> { - with_connection(&mut self.state, |params, _, connection| async move { + with_connection(&mut self.state, |params, circumstances, connection| async move { // We do not acquire advisory locks on PlanetScale instances. // // Advisory locking is supported on vitess (docs: @@ -81,6 +85,16 @@ impl SqlFlavour for MysqlFlavour { return Ok(()); } + // Do not acquire advisory locks on TiDB instances. + // + // As the TiDB Docker image used for testing does not contain the underlying storage + // engine TiKV, frequent write conflicts may occur in mock-kv, resulting in test failure. + // + // Issue: https://github.com/pingcap/tidb/issues/35155#issuecomment-1520428765 + if circumstances.contains(Circumstances::IsTiDB) { + return Ok(()); + } + // https://dev.mysql.com/doc/refman/8.0/en/locking-functions.html let query = format!("SELECT GET_LOCK('prisma_migrate', {})", ADVISORY_LOCK_TIMEOUT.as_secs()); connection.raw_cmd(&query, ¶ms.url).await @@ -150,7 +164,7 @@ impl SqlFlavour for MysqlFlavour { &self, datamodel: &ValidatedSchema, ) -> Option { - if self.is_mysql_5_6() { + if self.is_mysql_5_6() | self.is_tidb() { let mut errors = Vec::new(); check_datamodel_for_mysql_5_6(datamodel, &mut errors); @@ -429,6 +443,7 @@ pub(crate) enum Circumstances { IsMysql56, IsMariadb, IsVitess, + IsTiDB } fn check_datamodel_for_mysql_5_6(datamodel: &ValidatedSchema, errors: &mut Vec) { @@ -543,6 +558,10 @@ where if global_version.contains("MariaDB") { circumstances |= Circumstances::IsMariadb; } + + if version.contains("TiDB") { + circumstances |= Circumstances::IsTiDB; + } } let result_set = connection diff --git a/schema-engine/sql-introspection-tests/tests/tables/mod.rs b/schema-engine/sql-introspection-tests/tests/tables/mod.rs index 0853543a0f27..5b2c66767f4b 100644 --- a/schema-engine/sql-introspection-tests/tests/tables/mod.rs +++ b/schema-engine/sql-introspection-tests/tests/tables/mod.rs @@ -724,7 +724,7 @@ async fn expression_indexes_should_be_ignored_on_sqlite(api: &mut TestApi) -> Te Ok(()) } -// Exclude TiDB,because tidb's table names are not case sensitive. +// Exclude TiDB, because tidb's table names are not case sensitive. #[test_connector(tags(Mysql), exclude(Vitess, TiDB))] async fn casing_should_not_lead_to_mix_ups(api: &mut TestApi) -> TestResult { api.barrel() diff --git a/schema-engine/sql-migration-tests/tests/migrations/id.rs b/schema-engine/sql-migration-tests/tests/migrations/id.rs index 0b0e01087eb3..9fd13406fa18 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/id.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/id.rs @@ -185,7 +185,8 @@ fn models_with_an_autoincrement_field_as_part_of_a_multi_field_id_can_be_created } // Ignoring sqlite is OK, because sqlite integer primary keys are always auto-incrementing. -// Exclude TiDB, cannot set auto_increment through alter table, doc: https://docs.pingcap.com/tidb/dev/auto-increment#restrictions +// Exclude TiDB, cannot set auto_increment through alter table +// Doc: https://docs.pingcap.com/tidb/dev/auto-increment#restrictions #[test_connector(exclude(Sqlite, CockroachDb, TiDB))] fn making_an_existing_id_field_autoincrement_works(api: TestApi) { use quaint::ast::{Insert, Select}; diff --git a/schema-engine/sql-migration-tests/tests/migrations/relations.rs b/schema-engine/sql-migration-tests/tests/migrations/relations.rs index 8c8aa4075d51..e1b64c93e353 100644 --- a/schema-engine/sql-migration-tests/tests/migrations/relations.rs +++ b/schema-engine/sql-migration-tests/tests/migrations/relations.rs @@ -944,7 +944,7 @@ fn adding_mutual_references_on_existing_tables_works(api: TestApi) { let dm2 = r#" model A { - id Int @id + id Int name String @unique b_email String brel B @relation("AtoB", fields: [b_email], references: [email], onDelete: NoAction, onUpdate: NoAction) @@ -952,7 +952,7 @@ fn adding_mutual_references_on_existing_tables_works(api: TestApi) { } model B { - id Int @id + id Int email String @unique a_name String arel A @relation("BtoA", fields: [a_name], references: [name], onDelete: NoAction, onUpdate: NoAction) diff --git a/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs b/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs index 1e3ef67bd562..16b53ba3590a 100644 --- a/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs +++ b/schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs @@ -1,8 +1,9 @@ use crate::test_api::*; use pretty_assertions::assert_eq; use sql_schema_describer::*; +use test_setup::Tags::TiDB; -#[test_connector(tags(Mysql), exclude(TiDB))] +#[test_connector(tags(Mysql))] fn views_can_be_described(api: TestApi) { let sql = r#" CREATE TABLE a (a_id int); @@ -15,32 +16,18 @@ fn views_can_be_described(api: TestApi) { let result = api.describe(); let view = result.get_view("ab").expect("couldn't get ab view").to_owned(); - let expected_sql = format!( - "select `{0}`.`a`.`a_id` AS `a_id` from `{0}`.`a` union all select `{0}`.`b`.`b_id` AS `b_id` from `{0}`.`b`", - api.db_name() - ); - - assert_eq!("ab", &view.name); - assert_eq!(expected_sql, view.definition.unwrap()); -} - -#[test_connector(tags(TiDB))] -fn views_can_be_described_on_tidb(api: TestApi) { - let sql = r#" - CREATE TABLE a (a_id int); - CREATE TABLE b (b_id int); - CREATE VIEW ab AS - SELECT a_id FROM a UNION ALL SELECT b_id FROM b; - "#; - api.raw_cmd(sql); - - let result = api.describe(); - let view = result.get_view("ab").expect("couldn't get ab view").to_owned(); - - let expected_sql = format!( - "SELECT `a_id` AS `a_id` FROM `{0}`.`a` UNION ALL SELECT `b_id` AS `b_id` FROM `{0}`.`b`", - api.db_name() - ); + let expected_sql; + if api.connector_tags().contains(TiDB) { + expected_sql = format!( + "SELECT `a_id` AS `a_id` FROM `{0}`.`a` UNION ALL SELECT `b_id` AS `b_id` FROM `{0}`.`b`", + api.db_name() + ); + } else { + expected_sql = format!( + "select `{0}`.`a`.`a_id` AS `a_id` from `{0}`.`a` union all select `{0}`.`b`.`b_id` AS `b_id` from `{0}`.`b`", + api.db_name() + ); + } assert_eq!("ab", &view.name); assert_eq!(expected_sql, view.definition.unwrap()); @@ -3229,7 +3216,7 @@ fn all_tidb_column_types_must_work(api: TestApi) { api.expect_schema(expectation); } -#[test_connector(tags(Mysql), exclude(TiDB))] +#[test_connector(tags(Mysql))] fn mysql_foreign_key_on_delete_must_be_handled(api: TestApi) { // NB: We don't test the SET DEFAULT variety since it isn't supported on InnoDB and will // just cause an error @@ -3307,7 +3294,7 @@ fn mysql_join_table_unique_indexes_must_be_inferred(api: TestApi) { // When multiple databases exist on a mysql instance, and they share names for foreign key // constraints, introspecting one database should not yield constraints from the other. -// Exclude TiDB, because of the foreign key. +// Exclude TiDB, because the index name generated by TiDB for the foreign key is not consistent with MySQL. #[test_connector(tags(Mysql), exclude(TiDB))] fn constraints_from_other_databases_should_not_be_introspected(api: TestApi) { api.block_on(api.database().raw_cmd("DROP DATABASE `other_schema`")) @@ -4233,7 +4220,7 @@ fn function_expression_defaults_are_described_as_dbgenerated(api: TestApi) { api.expect_schema(expectation); } -#[test_connector(tags(Mysql), exclude(Mysql8, TiDB))] +#[test_connector(tags(Mysql), exclude(Mysql8))] fn dangling_foreign_keys_are_filtered_out(api: TestApi) { let setup = r#" SET FOREIGN_KEY_CHECKS=0; @@ -4261,16 +4248,30 @@ fn dangling_foreign_keys_are_filtered_out(api: TestApi) { .map(|fk| (fk.constraint_name(), fk.referenced_table().name())) .collect(); - let expectation = expect![[r#" - [ - ( - Some( - "dog_ibfk_2", - ), - "platypus", - ), - ] - "#]]; + let expectation; + if api.connector_tags().contains(TiDB) { + expectation = expect![[r#" + [ + ( + Some( + "fk_2", + ), + "platypus", + ), + ] + "#]]; + } else { + expectation = expect![[r#" + [ + ( + Some( + "dog_ibfk_2", + ), + "platypus", + ), + ] + "#]]; + } expectation.assert_debug_eq(&fks); } From 7d21e4f91fde04cce360de2c7a46b68eac732df6 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Wed, 26 Apr 2023 14:58:20 +0800 Subject: [PATCH 50/52] fix fmt --- .../connectors/sql-schema-connector/src/flavour/mysql.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs b/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs index 4e859b106d6e..67531c5ffe05 100644 --- a/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs +++ b/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs @@ -443,7 +443,7 @@ pub(crate) enum Circumstances { IsMysql56, IsMariadb, IsVitess, - IsTiDB + IsTiDB, } fn check_datamodel_for_mysql_5_6(datamodel: &ValidatedSchema, errors: &mut Vec) { From f61ed22108fe15ef977e22ef691ad1d40a0775bd Mon Sep 17 00:00:00 2001 From: Mini256 Date: Wed, 26 Apr 2023 17:46:57 +0800 Subject: [PATCH 51/52] fix --- .github/workflows/schema-engine.yml | 1 + .../sql-schema-connector/src/flavour/mysql.rs | 18 ++---------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/.github/workflows/schema-engine.yml b/.github/workflows/schema-engine.yml index 3c2dbe966969..06092882dbdd 100644 --- a/.github/workflows/schema-engine.yml +++ b/.github/workflows/schema-engine.yml @@ -72,6 +72,7 @@ jobs: url: "mysql://root:prisma@localhost:3308" - name: tidb url: "mysql://root@localhost:4000" + single_threaded: true - name: postgres9 url: "postgresql://postgres:prisma@localhost:5431" - name: postgres10 diff --git a/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs b/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs index 67531c5ffe05..269d8f69df47 100644 --- a/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs +++ b/schema-engine/connectors/sql-schema-connector/src/flavour/mysql.rs @@ -51,10 +51,6 @@ impl MysqlFlavour { self.circumstances().contains(Circumstances::IsMysql56) } - pub(crate) fn is_tidb(&self) -> bool { - self.circumstances().contains(Circumstances::IsTiDB) - } - pub(crate) fn lower_cases_table_names(&self) -> bool { self.circumstances().contains(Circumstances::LowerCasesTableNames) } @@ -73,7 +69,7 @@ impl MysqlFlavour { impl SqlFlavour for MysqlFlavour { fn acquire_lock(&mut self) -> BoxFuture<'_, ConnectorResult<()>> { - with_connection(&mut self.state, |params, circumstances, connection| async move { + with_connection(&mut self.state, |params, _, connection| async move { // We do not acquire advisory locks on PlanetScale instances. // // Advisory locking is supported on vitess (docs: @@ -85,16 +81,6 @@ impl SqlFlavour for MysqlFlavour { return Ok(()); } - // Do not acquire advisory locks on TiDB instances. - // - // As the TiDB Docker image used for testing does not contain the underlying storage - // engine TiKV, frequent write conflicts may occur in mock-kv, resulting in test failure. - // - // Issue: https://github.com/pingcap/tidb/issues/35155#issuecomment-1520428765 - if circumstances.contains(Circumstances::IsTiDB) { - return Ok(()); - } - // https://dev.mysql.com/doc/refman/8.0/en/locking-functions.html let query = format!("SELECT GET_LOCK('prisma_migrate', {})", ADVISORY_LOCK_TIMEOUT.as_secs()); connection.raw_cmd(&query, ¶ms.url).await @@ -164,7 +150,7 @@ impl SqlFlavour for MysqlFlavour { &self, datamodel: &ValidatedSchema, ) -> Option { - if self.is_mysql_5_6() | self.is_tidb() { + if self.is_mysql_5_6() { let mut errors = Vec::new(); check_datamodel_for_mysql_5_6(datamodel, &mut errors); From fed4a9b7a22b905d7a136803b4b49251c134d782 Mon Sep 17 00:00:00 2001 From: Mini256 Date: Wed, 5 Jul 2023 18:37:20 +0800 Subject: [PATCH 52/52] feat: update the tidb image to v7.1.0 --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1691df2d590c..1bcd5cb9821a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -181,7 +181,7 @@ services: tmpfs: /var/lib/mariadb tidb: - image: pingcap/tidb:v7.0.0 + image: pingcap/tidb:v7.1.0 restart: always platform: linux/x86_64 ports: