Skip to content

Commit

Permalink
tests: cockroachdb 23.1 (#4132)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Orlenko <alex@aqrln.net>
  • Loading branch information
Jolg42 and aqrln committed Aug 28, 2023
1 parent db53943 commit 08cc777
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/query-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
single_threaded: true
connector: "mongodb"
version: "4.2"
- name: "cockroach_23_1"
single_threaded: false
connector: "cockroachdb"
version: "23.1"
- name: "cockroach_22_2"
single_threaded: false
connector: "cockroachdb"
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/schema-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ jobs:
url: "postgresql://postgres:prisma@localhost:5437"
- name: postgres15
url: "postgresql://postgres:prisma@localhost:5438"
- name: cockroach_23_1
url: "postgresql://prisma@localhost:26260"
- name: cockroach_22_2
url: "postgresql://prisma@localhost:26259"
- name: cockroach_22_1_0
Expand Down
2 changes: 1 addition & 1 deletion .test_database_urls/cockroachdb_23_1
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export TEST_DATABASE_URL="postgresql://prisma@localhost:26260"

unset TEST_SHADOW_DATABASE_URL
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ start-postgres15:
dev-postgres15: start-postgres15
cp $(CONFIG_PATH)/postgres15 $(CONFIG_FILE)

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

dev-cockroach_23_1: start-cockroach_23_1
cp $(CONFIG_PATH)/cockroach_23_1 $(CONFIG_FILE)

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

Expand Down
8 changes: 5 additions & 3 deletions libs/test-setup/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ pub(crate) fn get_postgres_tags(database_url: &str) -> Result<BitFlags<Tags>, St
}

if version.contains("CockroachDB") {
if version.contains("v22.2") {
tags |= Tags::CockroachDb222
if version.contains("v23.1") {
tags |= Tags::CockroachDb231;
} else if version.contains("v22.2") {
tags |= Tags::CockroachDb222;
} else if version.contains("v21.2") {
tags |= Tags::CockroachDb221
tags |= Tags::CockroachDb221;
}

tags |= Tags::CockroachDb;
Expand Down
1 change: 1 addition & 0 deletions libs/test-setup/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tags![
Postgres13 = 1 << 18,
CockroachDb221 = 1 << 19,
CockroachDb222 = 1 << 20,
CockroachDb231 = 1 << 21,
];

pub fn tags_from_comma_separated_list(input: &str) -> BitFlags<Tags> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub(crate) struct CockroachDbConnectorTag;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CockroachDbVersion {
V231,
V222,
V221,
}
Expand All @@ -19,6 +20,7 @@ impl TryFrom<&str> for CockroachDbVersion {
let version = match s {
"22.1" => Self::V221,
"22.2" => Self::V222,
"23.1" => Self::V231,
_ => return Err(TestError::parse_error(format!("Unknown CockroachDB version `{s}`"))),
};

Expand All @@ -29,6 +31,7 @@ impl TryFrom<&str> for CockroachDbVersion {
impl fmt::Display for CockroachDbVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
CockroachDbVersion::V231 => f.write_str("23.1"),
CockroachDbVersion::V222 => f.write_str("22.2"),
CockroachDbVersion::V221 => f.write_str("22.1"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,18 @@ pub(crate) fn connection_string(
Some(CockroachDbVersion::V222) if is_ci => {
format!("postgresql://prisma@test-db-cockroachdb-22-2:26259/{database}?schema={database}")
}
Some(CockroachDbVersion::V231) if is_ci => {
format!("postgresql://prisma@test-db-cockroachdb-23-1:26260/{database}?schema={database}")
}
Some(CockroachDbVersion::V221) => {
format!("postgresql://prisma@127.0.0.1:26257/{database}?schema={database}")
}
Some(CockroachDbVersion::V222) => {
format!("postgresql://prisma@127.0.0.1:26259/{database}?schema={database}")
}
Some(CockroachDbVersion::V231) => {
format!("postgresql://prisma@127.0.0.1:26260/{database}?schema={database}")
}

None => unreachable!("A versioned connector must have a concrete version to run."),
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"connector": "cockroachdb",
"version": "23.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ fn bigint_defaults_work(api: TestApi) {
}

// regression test for https://github.com/prisma/prisma/issues/20557
#[test_connector(tags(CockroachDb))]
#[test_connector(tags(CockroachDb), exclude(CockroachDb231))]
fn alter_type_works(api: TestApi) {
let schema = r#"
datasource db {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sql_migration_tests::test_api::*;

#[test_connector(tags(CockroachDb))]
#[test_connector(tags(CockroachDb), exclude(CockroachDb231))]
fn failing_migration_after_migration_dropping_data(api: TestApi) {
let migrations = &[
r#"
Expand Down Expand Up @@ -49,7 +49,7 @@ fn failing_migration_after_migration_dropping_data(api: TestApi) {
expectation.assert_eq(&err);
}

#[test_connector(tags(CockroachDb))]
#[test_connector(tags(CockroachDb), exclude(CockroachDb231))]
fn failing_step_in_migration_dropping_data(api: TestApi) {
let migrations = &[
r#"
Expand Down Expand Up @@ -96,7 +96,8 @@ fn failing_step_in_migration_dropping_data(api: TestApi) {
expectation.assert_eq(&err);
}

#[test_connector(tags(CockroachDb))]
// Skipped on CRDB 23.1 because of https://github.com/prisma/prisma/issues/20851
#[test_connector(tags(CockroachDb), exclude(CockroachDb231))]
fn multiple_alter_tables_in_one_migration_works(api: TestApi) {
let migrations = &[
r#"
Expand Down Expand Up @@ -170,7 +171,7 @@ fn multiple_alter_tables_in_multiple_migration_works(api: TestApi) {
api.apply_migrations(&dir).send_sync();
}

#[test_connector(tags(CockroachDb))]
#[test_connector(tags(CockroachDb), exclude(CockroachDb231))]
fn syntax_errors_return_error_position(api: TestApi) {
let migrations = &[r#"
CREATE TABLE "Dog" (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,8 @@ fn multi_schema_tests(_api: TestApi) {
async fn migration_with_shadow_database() {
let conn_str = std::env::var("TEST_DATABASE_URL").unwrap();

if !conn_str.starts_with("postgres") || conn_str.contains("localhost:2625") {
let is_cockroach = conn_str.contains("localhost:2625") || conn_str.contains("localhost:26260");
if !conn_str.starts_with("postgres") || is_cockroach {
return;
}

Expand Down

0 comments on commit 08cc777

Please sign in to comment.