Skip to content

Commit

Permalink
Cockroach CI integration (#2423)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpetrick authored Nov 26, 2021
1 parent b7c2abe commit 13f3d22
Show file tree
Hide file tree
Showing 23 changed files with 125 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .buildkite/engineer
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
if ! type "engineer" > /dev/null; then
# Setup Prisma engine build & test tool (engineer).
set -e
curl --fail -sSL "https://prisma-engineer.s3-eu-west-1.amazonaws.com/1.29/latest/$OS/engineer.gz" --output engineer.gz
curl --fail -sSL "https://prisma-engineer.s3-eu-west-1.amazonaws.com/1.30/latest/$OS/engineer.gz" --output engineer.gz
gzip -d engineer.gz
chmod +x engineer

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/migration-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ jobs:
CLICOLOR_FORCE: 1
TEST_DATABASE_URL: ${{ matrix.database.url }}


test-linux:
name: "Test ${{ matrix.database.name }} on Linux"

Expand Down Expand Up @@ -80,7 +79,7 @@ jobs:
- name: postgres14
url: "postgresql://postgres:prisma@localhost:5437"
- name: cockroach
url: "postgresql://root@localhost:5436"
url: "postgresql://root@localhost:26257"
is_cockroach: true
- name: sqlite
url: sqlite
Expand Down
2 changes: 1 addition & 1 deletion .test_database_urls/cockroachdb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export TEST_DATABASE_URL="postgresql://root@localhost:5436"
export TEST_DATABASE_URL="postgresql://prisma@localhost:26257"
unset TEST_SHADOW_DATABASE_URL
22 changes: 0 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,104 +50,87 @@ all-dbs-down:
start-sqlite:

dev-sqlite:
echo 'sqlite' > current_connector
cp $(CONFIG_PATH)/sqlite $(CONFIG_FILE)

start-postgres9:
docker-compose -f docker-compose.yml up -d --remove-orphans postgres9

dev-postgres9: start-postgres9
echo 'postgres9' > current_connector
cp $(CONFIG_PATH)/postgres9 $(CONFIG_FILE)

start-postgres10:
docker-compose -f docker-compose.yml up -d --remove-orphans postgres10

dev-postgres10: start-postgres10
echo 'postgres10' > current_connector
cp $(CONFIG_PATH)/postgres10 $(CONFIG_FILE)

start-postgres11:
docker-compose -f docker-compose.yml up -d --remove-orphans postgres11

dev-postgres11: start-postgres11
echo 'postgres11' > current_connector
cp $(CONFIG_PATH)/postgres11 $(CONFIG_FILE)

start-postgres12:
docker-compose -f docker-compose.yml up -d --remove-orphans postgres12

dev-postgres12: start-postgres12
echo 'postgres12' > current_connector
cp $(CONFIG_PATH)/postgres12 $(CONFIG_FILE)

start-postgres13:
docker-compose -f docker-compose.yml up -d --remove-orphans postgres13

dev-postgres13: start-postgres13
echo 'postgres13' > current_connector
cp $(CONFIG_PATH)/postgres13 $(CONFIG_FILE)

start-postgres14:
docker-compose -f docker-compose.yml up -d --remove-orphans postgres14

dev-postgres14: start-postgres14
echo 'postgres14' > current_connector
cp $(CONFIG_PATH)/postgres14 $(CONFIG_FILE)

start-cockroach:
docker-compose -f docker-compose.yml up -d --remove-orphans cockroach
docker exec -d prisma-engines_cockroach_1 cockroach sql --insecure -e "set cluster setting sql.defaults.default_int_size = 4;"
docker exec -d prisma-engines_cockroach_1 cockroach sql --insecure -e "set cluster setting sql.defaults.serial_normalization = 'sql_sequence_cached';"

dev-cockroach: start-cockroach
echo 'cockroach' > current_connector
cp $(CONFIG_PATH)/cockroach $(CONFIG_FILE)

dev-pgbouncer:
docker-compose -f docker-compose.yml up -d --remove-orphans pgbouncer postgres11
echo 'pgbouncer' > current_connector

start-mysql_5_7:
docker-compose -f docker-compose.yml up -d --remove-orphans mysql-5-7

dev-mysql: start-mysql_5_7
echo 'mysql' > current_connector
cp $(CONFIG_PATH)/mysql57 $(CONFIG_FILE)

start-mysql_5_6:
docker-compose -f docker-compose.yml up -d --remove-orphans mysql-5-6

dev-mysql_5_6: start-mysql_5_6
echo 'mysql56' > current_connector
cp $(CONFIG_PATH)/mysql56 $(CONFIG_FILE)

start-mysql_8:
docker-compose -f docker-compose.yml up -d --remove-orphans mysql-8-0

dev-mysql8: start-mysql_8
echo 'mysql8' > current_connector
cp $(CONFIG_PATH)/mysql8 $(CONFIG_FILE)

start-mysql_mariadb:
docker-compose -f docker-compose.yml up -d --remove-orphans mariadb-10-0

dev-mariadb: start-mysql_mariadb
echo 'mariadb' > current_connector
cp $(CONFIG_PATH)/mariadb $(CONFIG_FILE)

start-mssql_2019:
docker-compose -f docker-compose.yml up -d --remove-orphans mssql-2019

dev-mssql2019: start-mssql_2019
echo 'mssql2019' > current_connector
cp $(CONFIG_PATH)/sqlserver2019 $(CONFIG_FILE)

start-mssql_2017:
docker-compose -f docker-compose.yml up -d --remove-orphans mssql-2017

dev-mssql2017: start-mssql_2017
echo 'mssql2017' > current_connector
cp $(CONFIG_PATH)/sqlserver2017 $(CONFIG_FILE)

start-mongodb4-single:
Expand All @@ -163,32 +146,27 @@ start-mongodb_4_4:
docker-compose -f docker-compose.yml up -d --remove-orphans mongo44

dev-mongodb_4_4: start-mongodb_4_4
echo 'mongodb' > current_connector
cp $(CONFIG_PATH)/mongodb44 $(CONFIG_FILE)

start-mongodb_5:
docker-compose -f docker-compose.yml up -d --remove-orphans mongo5

dev-mongodb_5: start-mongodb_5
echo 'mongodb' > current_connector
cp $(CONFIG_PATH)/mongodb5 $(CONFIG_FILE)

dev-mongodb_4_2: start-mongodb_4_2
echo 'mongodb' > current_connector
cp $(CONFIG_PATH)/mongodb42 $(CONFIG_FILE)

start-vitess_5_7:
docker-compose -f docker-compose.yml up -d --remove-orphans vitess-test-5_7 vitess-shadow-5_7

dev-vitess_5_7: start-vitess_5_7
echo 'vitess_5_7' > current_connector
cp $(CONFIG_PATH)/vitess_5_7 $(CONFIG_FILE)

start-vitess_8_0:
docker-compose -f docker-compose.yml up -d --remove-orphans vitess-test-8_0 vitess-shadow-8_0

dev-vitess_8_0: start-vitess_8_0
echo 'vitess_8_0' > current_connector
cp $(CONFIG_PATH)/vitess_8_0 $(CONFIG_FILE)

######################
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: "3"
services:
cockroach:
image: otanatcockroach/cockroachdb-custom:v1
image: prismagraphql/build:cockroach-custom
restart: always
command: start-single-node --insecure
ports:
- "5436:26257"
- "26257:26257"
networks:
- databases

Expand Down Expand Up @@ -310,9 +310,9 @@ services:
# Jaeger supports OTEL out of the box
image: jaegertracing/opentelemetry-all-in-one:latest
ports:
- 13133:13133 # health check port
- 16686:16686 # UI viewer
- 4317:55680 # Otel endpoint
- 13133:13133 # health check port
- 16686:16686 # UI viewer
- 4317:55680 # Otel endpoint

networks:
databases:
databases: null
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ pub(crate) trait SqlFlavour:
/// schema we connect to exists.
async fn ensure_connection_validity(&self, connection: &Connection) -> ConnectorResult<()>;

/// Perform the initialization required by connector-test-kit tests.
/// Perform the initialization required by connector-test-kit-rs tests.
async fn qe_setup(&self, database_url: &str) -> ConnectorResult<()>;

/// Perform teardown required by connector-test-kit-rs tests.
async fn qe_teardown(&self, database_url: &str) -> ConnectorResult<()>;

/// Drop the database and recreate it empty.
async fn reset(&self, connection: &Connection) -> ConnectorResult<()>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ impl SqlFlavour for MssqlFlavour {
Ok(())
}

async fn qe_teardown(&self, _database_str: &str) -> ConnectorResult<()> {
Ok(())
}

async fn ensure_connection_validity(&self, connection: &Connection) -> ConnectorResult<()> {
connection.raw_cmd("SELECT 1").await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ impl SqlFlavour for MysqlFlavour {
Ok(())
}

async fn qe_teardown(&self, _database_str: &str) -> ConnectorResult<()> {
Ok(())
}

async fn reset(&self, connection: &Connection) -> ConnectorResult<()> {
if self.is_vitess() {
return Err(ConnectorError::from_msg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ impl SqlFlavour for PostgresFlavour {
Ok(())
}

async fn qe_teardown(&self, database_str: &str) -> ConnectorResult<()> {
let mut url = Url::parse(database_str).map_err(ConnectorError::url_parse_error)?;
strip_schema_param_from_url(&mut url);

let conn = create_postgres_admin_conn(url.clone()).await?;
let db_name = self.url.dbname();

let query = format!("DROP DATABASE \"{}\" CASCADE", db_name);
conn.raw_cmd(&query).await.ok();

Ok(())
}

async fn reset(&self, connection: &Connection) -> ConnectorResult<()> {
let schema_name = connection.connection_info().schema_name();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl SqlFlavour for SqliteFlavour {
Ok(())
}

async fn qe_teardown(&self, _database_str: &str) -> ConnectorResult<()> {
Ok(())
}

async fn reset(&self, connection: &Connection) -> ConnectorResult<()> {
let connection_info = connection.connection_info();
let file_path = connection_info.file_path().unwrap();
Expand Down
11 changes: 9 additions & 2 deletions migration-engine/connectors/sql-migration-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,22 @@ impl SqlMigrationConnector {
})
}

/// Set up the database for connector-test-kit, without initializing the connector.
/// Set up the database for connector-test-kit-rs, without initializing the connector.
pub async fn qe_setup(database_str: &str) -> ConnectorResult<()> {
let connection_info = ConnectionInfo::from_url(database_str).map_err(ConnectorError::url_parse_error)?;

let flavour = flavour::from_connection_info(&connection_info, BitFlags::empty());

flavour.qe_setup(database_str).await
}

/// Tear down the database for connector-test-kit-rs, without initializing the connector.
pub async fn qe_teardown(database_str: &str) -> ConnectorResult<()> {
let connection_info = ConnectionInfo::from_url(database_str).map_err(ConnectorError::url_parse_error)?;
let flavour = flavour::from_connection_info(&connection_info, BitFlags::empty());

flavour.qe_teardown(database_str).await
}

async fn conn(&self) -> ConnectorResult<&Connection> {
self.connection
.get_or_init(|| {
Expand Down
2 changes: 1 addition & 1 deletion migration-engine/core/src/native.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod rpc;

pub mod qe_setup;
pub mod query_engine;

pub use crate::api::GenericApi;
pub use rpc::rpc_api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use migration_connector::{ConnectorResult, DiffTarget, MigrationConnector};
use mongodb_migration_connector::MongoDbMigrationConnector;
use sql_migration_connector::SqlMigrationConnector;

/// Database setup for connector-test-kit.
pub async fn run(prisma_schema: &str) -> ConnectorResult<()> {
/// Database setup for connector-test-kit-rs.
pub async fn setup(prisma_schema: &str) -> ConnectorResult<()> {
let (source, url, preview_features, _shadow_database_url) = super::parse_configuration(prisma_schema)?;

match &source.active_provider {
Expand Down Expand Up @@ -41,6 +41,7 @@ pub async fn run(prisma_schema: &str) -> ConnectorResult<()> {
.unwrap();
};
}

#[cfg(feature = "mongodb")]
provider if provider == MONGODB_SOURCE_NAME => {
let connector = MongoDbMigrationConnector::new(url, preview_features);
Expand All @@ -49,6 +50,33 @@ pub async fn run(prisma_schema: &str) -> ConnectorResult<()> {
let (_, schema) = crate::parse_schema(prisma_schema).unwrap();
connector.create_collections(&schema).await?;
}

x => unimplemented!("Connector {} is not supported yet", x),
};

Ok(())
}

/// Database teardown for connector-test-kit-rs.
pub async fn teardown(prisma_schema: &str) -> ConnectorResult<()> {
let (source, url, _, _) = super::parse_configuration(prisma_schema)?;

match &source.active_provider {
provider
if [
MYSQL_SOURCE_NAME,
POSTGRES_SOURCE_NAME,
SQLITE_SOURCE_NAME,
MSSQL_SOURCE_NAME,
]
.contains(&provider.as_str()) =>
{
SqlMigrationConnector::qe_teardown(&url).await?;
}

#[cfg(feature = "mongodb")]
provider if provider == MONGODB_SOURCE_NAME => {}

x => unimplemented!("Connector {} is not supported yet", x),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ mod order_by_dependent {
[MongoDb, Sqlite] => r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":null}},{"id":3,"b":null},{"id":1,"b":{"c":{"id":1}}}]}}"#,
[SqlServer, MySql] => r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":2,"b":{"c":null}},{"id":1,"b":{"c":{"id":1}}}]}}"#,
[Postgres] => r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}},{"id":2,"b":{"c":null}},{"id":3,"b":null}]}}"#,
// CockroachDB can order ModelA.id in any order if ModelC.b_id is NULL.
// CockroachDB can order ModelA.id in any order if ModelC.b_id is NULL.
[Postgres] => r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"id":1}}},{"id":3,"b":null},{"id":2,"b":{"c":null}}]}}"#,
[MySql] => r#"{"data":{"findManyModelA":[{"id":2,"b":{"c":null}},{"id":3,"b":null},{"id":1,"b":{"c":{"id":1}}}]}}"#
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ mod order_by_dependent_pag {
}"#, // Depends on how null values are handled.
[MongoDb] => r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}}]}}"#,
[Postgres] => 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}]}}"#,
// CockroachDB can order ModelA.id in any order if ModelB.a_id is NULL.
// CockroachDB can order ModelA.id in any order if ModelB.a_id is NULL.
[Postgres] => r#"{"data":{"findManyModelA":[{"id":1,"b":{"c":{"a":{"id":3}}}},{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":4,"b":null},{"id":3,"b":null}]}}"#,
// Mariadb
[Sqlite, MySql] => 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}}}}]}}"#,
Expand Down Expand Up @@ -285,8 +285,10 @@ mod order_by_dependent_pag {
}
}"#,
// Depends on how null values are handled.
[MongoDb, Sqlite, MySql] => 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}]}}"#,
[Postgres] => r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}}]}}"#
[MongoDb, Sqlite, MySql, Postgres] => 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}]}}"#,
[Postgres] => r#"{"data":{"findManyModelA":[{"id":3,"b":null},{"id":4,"b":null},{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}}]}}"#,
// Cockroach has a different ordering.
[Postgres] => r#"{"data":{"findManyModelA":[{"id":4,"b":null},{"id":3,"b":null},{"id":2,"b":{"c":{"a":{"id":4}}}},{"id":1,"b":{"c":{"a":{"id":3}}}}]}}"#
);
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use query_engine_tests::*;

#[test_suite(schema(schema), capabilities(FullTextSearchWithoutIndex))]
#[test_suite(schema(schema), capabilities(FullTextSearchWithoutIndex), exclude(Cockroach))]
mod order_by_relevance {
use indoc::indoc;
use query_engine_tests::{assert_error, run_query};
Expand All @@ -15,7 +15,7 @@ mod order_by_relevance {
fieldC String?
relations Relation[]
}
model Relation {
#id(id, Int, @id)
testModel TestModel? @relation(fields: [testModelId], references: [id])
Expand Down
Loading

0 comments on commit 13f3d22

Please sign in to comment.