Skip to content

Commit

Permalink
test: add Postgres v16 to GitHub Actions tests (#4324)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
  • Loading branch information
Jolg42 and janpio authored Dec 15, 2023
1 parent 626c13b commit e2ce1ac
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test-query-engine-black-box.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ jobs:
fail-fast: false
matrix:
database:
- name: 'postgres15'
- name: 'postgres16'
single_threaded: false
connector: 'postgres'
version: '15'
# Arbitrary PostgreSQL version
# we opted for the most recent one, there is no need to have a matrix
version: '16'

env:
LOG_LEVEL: 'info'
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/test-query-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ jobs:
single_threaded: true
connector: 'vitess'
version: '8.0'
- name: 'postgres15'
# Arbitrary PostgreSQL version
# we opted for the most recent one, there is no need to have a matrix
- name: 'postgres16'
single_threaded: true
connector: 'postgres'
version: '15'
version: '16'
- name: 'mssql_2022'
single_threaded: false
connector: 'sqlserver'
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test-schema-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ jobs:
url: 'postgresql://postgres:prisma@localhost:5437'
- name: postgres15
url: 'postgresql://postgres:prisma@localhost:5438'
- name: postgres16
url: 'postgresql://postgres:prisma@localhost:5439'
- name: cockroach_23_1
url: 'postgresql://prisma@localhost:26260'
- name: cockroach_22_2
Expand Down Expand Up @@ -144,6 +146,9 @@ jobs:
CLICOLOR_FORCE: 1
TEST_DATABASE_URL: ${{ matrix.database.url }}

#
# Vitess tests
#
- run: cargo test -p sql-introspection-tests -- --test-threads=1
if: ${{ matrix.database.is_vitess }}
env:
Expand All @@ -166,6 +171,9 @@ jobs:
TEST_DATABASE_URL: ${{ matrix.database.url }}
TEST_SHADOW_DATABASE_URL: ${{ matrix.database.shadow_database_url }}

#
# Single threaded tests (excluding Vitess)
#
- run: cargo test -p sql-schema-describer -- --test-threads=1
if: ${{ !matrix.database.is_vitess && matrix.database.single_threaded }}
env:
Expand Down
1 change: 1 addition & 0 deletions .test_database_urls/postgres_16
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export TEST_DATABASE_URL="postgresql://postgres:prisma@localhost:5439"
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ start-postgres15:
dev-postgres15: start-postgres15
cp $(CONFIG_PATH)/postgres15 $(CONFIG_FILE)

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

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

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

Expand Down
23 changes: 18 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ services:
- databases
tmpfs: /var/lib/planetscale-mysql
volumes:
- "./docker/planetscale-mysql/my.cnf:/etc/mysql/my.cnf"
- './docker/planetscale-mysql/my.cnf:/etc/mysql/my.cnf'
ulimits:
nofile:
soft: 20000
hard: 40000
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
timeout: 20s
retries: 10

Expand Down Expand Up @@ -213,6 +213,19 @@ services:
networks:
- databases

postgres16:
image: postgres:16
restart: unless-stopped
command: postgres -c 'max_connections=1000'
environment:
POSTGRES_PASSWORD: 'prisma'
POSTGRES_HOST_AUTH_METHOD: 'md5'
POSTGRES_INITDB_ARGS: '--auth-host=md5'
ports:
- '5439:5432'
networks:
- databases

mysql-5-6:
image: mysql:5.6.50
command: mysqld
Expand All @@ -228,7 +241,7 @@ services:
- databases
tmpfs: /var/lib/mysql
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
timeout: 20s
retries: 10

Expand All @@ -246,7 +259,7 @@ services:
- databases
tmpfs: /var/lib/mysql
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
timeout: 20s
retries: 10

Expand All @@ -264,7 +277,7 @@ services:
- databases
tmpfs: /var/lib/mysql8
healthcheck:
test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
timeout: 20s
retries: 10

Expand Down
4 changes: 4 additions & 0 deletions libs/test-setup/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub(crate) fn get_postgres_tags(database_url: &str) -> Result<BitFlags<Tags>, St
tags |= Tags::Postgres15;
}

if version.contains("PostgreSQL 16") {
tags |= Tags::Postgres16;
}

if version.contains("CockroachDB") {
if version.contains("v23.1") {
tags |= Tags::CockroachDb231;
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 @@ -41,6 +41,7 @@ tags![
CockroachDb221 = 1 << 19,
CockroachDb222 = 1 << 20,
CockroachDb231 = 1 << 21,
Postgres16 = 1 << 22,
];

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 @@ -127,6 +127,7 @@ pub(crate) fn connection_string(
}
Some(PostgresVersion::V14) => format!("postgresql://postgres:prisma@127.0.0.1:5437/{database}"),
Some(PostgresVersion::V15) => format!("postgresql://postgres:prisma@127.0.0.1:5438/{database}"),
Some(PostgresVersion::V16) => format!("postgresql://postgres:prisma@127.0.0.1:5439/{database}"),
Some(PostgresVersion::PgBouncer) => {
format!("postgresql://postgres:prisma@127.0.0.1:6432/db?{database}&pgbouncer=true")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum PostgresVersion {
V13,
V14,
V15,
V16,
PgBouncer,
NeonJsNapi,
PgJsNapi,
Expand All @@ -54,6 +55,7 @@ impl TryFrom<&str> for PostgresVersion {
"13" => Self::V13,
"14" => Self::V14,
"15" => Self::V15,
"16" => Self::V16,
"pgbouncer" => Self::PgBouncer,
"neon.js" => Self::NeonJsNapi,
"pg.js" => Self::PgJsNapi,
Expand All @@ -76,6 +78,7 @@ impl ToString for PostgresVersion {
PostgresVersion::V13 => "13",
PostgresVersion::V14 => "14",
PostgresVersion::V15 => "15",
PostgresVersion::V16 => "16",
PostgresVersion::PgBouncer => "pgbouncer",
PostgresVersion::NeonJsNapi => "neon.js",
PostgresVersion::PgJsNapi => "pg.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async fn ignore_on_back_relation_field_if_pointing_to_ignored_model(api: &mut Te
// Postgres9 does not support partition tables, and Postgres10 does not support primary keys on
// partition tables without an workaround (see the following tests for details).
#[test_connector(
tags(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15),
tags(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15, Postgres16),
exclude(CockroachDb)
)]
async fn partition_table_gets_comment(api: &mut TestApi) -> TestResult {
Expand Down
2 changes: 1 addition & 1 deletion schema-engine/sql-introspection-tests/tests/tables/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ async fn default_values(api: &mut TestApi) -> TestResult {
Ok(())
}

#[test_connector(tags(Postgres), exclude(CockroachDb, Postgres14, Postgres15))]
#[test_connector(tags(Postgres), exclude(CockroachDb, Postgres14, Postgres15, Postgres16))]
async fn pg_default_value_as_dbgenerated(api: &mut TestApi) -> TestResult {
let sequence = "CREATE SEQUENCE test_seq START 1".to_string();
api.database().execute_raw(&sequence, &[]).await?;
Expand Down
77 changes: 76 additions & 1 deletion schema-engine/sql-introspection-tests/tests/views/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ async fn preview_feature_is_required(api: &mut TestApi) -> TestResult {
Ok(())
}

#[test_connector(tags(Postgres), exclude(CockroachDb), preview_features("views"))]
// See next test after this one for PostgreSQL 16
#[test_connector(tags(Postgres), exclude(Postgres16), exclude(CockroachDb), preview_features("views"))]
async fn simple_view_from_one_table(api: &mut TestApi) -> TestResult {
let setup = indoc! {r#"
CREATE TABLE "User" (
Expand Down Expand Up @@ -103,6 +104,80 @@ async fn simple_view_from_one_table(api: &mut TestApi) -> TestResult {
Ok(())
}

// PostgreSQL 16 only
// the expect_view_definition is slightly different than for previous versions
#[test_connector(tags(Postgres16), preview_features("views"))]
async fn simple_view_from_one_table_postgres16(api: &mut TestApi) -> TestResult {
let setup = indoc! {r#"
CREATE TABLE "User" (
id SERIAL PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NULL
);
CREATE VIEW "Schwuser" AS
SELECT id, first_name, last_name FROM "User";
"#};

api.raw_cmd(setup).await;

let expected = expect![[r#"
generator client {
provider = "prisma-client-js"
previewFeatures = ["views"]
}
datasource db {
provider = "postgresql"
url = "env(TEST_DATABASE_URL)"
}
model User {
id Int @id @default(autoincrement())
first_name String @db.VarChar(255)
last_name String? @db.VarChar(255)
}
/// The underlying view does not contain a valid unique identifier and can therefore currently not be handled by Prisma Client.
view Schwuser {
id Int?
first_name String? @db.VarChar(255)
last_name String? @db.VarChar(255)
@@ignore
}
"#]];

api.expect_datamodel(&expected).await;

// For Postgres <16 it looks like this:
// SELECT
// "User".id,
// "User".first_name,
// "User".last_name
// FROM
// "User";
let expected = expect![[r#"
SELECT
id,
first_name,
last_name
FROM
"User";"#]];

api.expect_view_definition("Schwuser", &expected).await;

let expected = expect![[r#"
*** WARNING ***
The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers
- "Schwuser"
"#]];
api.expect_warnings(&expected).await;

Ok(())
}

#[test_connector(tags(Postgres), exclude(CockroachDb), preview_features("views"))]
async fn simple_view_from_two_tables(api: &mut TestApi) -> TestResult {
let setup = indoc! {r#"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ impl TestApi {
self.tags().contains(Tags::Postgres15)
}

/// Returns true only when testing on postgres version 16.
pub fn is_postgres_16(&self) -> bool {
self.tags().contains(Tags::Postgres16)
}

/// Returns true only when testing on cockroach.
pub fn is_cockroach(&self) -> bool {
self.tags().contains(Tags::CockroachDb)
Expand Down
5 changes: 5 additions & 0 deletions schema-engine/sql-migration-tests/src/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ impl TestApi {
self.root.is_postgres_15()
}

/// Returns true only when testing on postgres version 16.
pub fn is_postgres_16(&self) -> bool {
self.root.is_postgres_16()
}

/// Returns true only when testing on cockroach.
pub fn is_cockroach(&self) -> bool {
self.root.is_cockroach()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ fn alter_constraint_name(mut api: TestApi) {
let is_mssql = api.is_mssql();
let is_postgres = api.is_postgres();
let is_postgres15 = api.is_postgres_15();
let is_postgres16 = api.is_postgres_16();
let is_cockroach = api.is_cockroach();
let is_sqlite = api.is_sqlite();

Expand Down Expand Up @@ -1099,7 +1100,7 @@ fn alter_constraint_name(mut api: TestApi) {
-- RenameIndex
ALTER INDEX "B_a_b_idx" RENAME TO "AnotherCustomIndex";
"#]]
} else if is_postgres15 {
} else if is_postgres15 || is_postgres16 {
expect![[r#"
-- AlterTable
ALTER TABLE "A" RENAME CONSTRAINT "A_pkey" TO "CustomId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sql_migration_tests::test_api::*;
fn introspect_partition_tables() {
// Postgres9 does not support partition tables, and Postgres10 does not support primary keys on
// partition tables.
let test_db = test_setup::only!(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15 ; exclude: CockroachDb);
let test_db = test_setup::only!(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15, Postgres16 ; exclude: CockroachDb);
let (_, url_str) = tok(test_setup::postgres::create_postgres_database(
test_db.url(),
"postgres_introspect_partition_tables",
Expand Down Expand Up @@ -84,7 +84,7 @@ model blocks {{
fn inherited_table_regression_fix() {
// Postgres9 does not support partition tables, and Postgres10 does not support primary keys on
// partition tables.
let test_db = test_setup::only!(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15 ; exclude: CockroachDb);
let test_db = test_setup::only!(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15, Postgres16 ; exclude: CockroachDb);
let (_, url_str) = tok(test_setup::postgres::create_postgres_database(
test_db.url(),
"inherited_table_regression_fix",
Expand Down Expand Up @@ -155,7 +155,7 @@ model cities {{

#[test]
fn inherited_table_detect_primary_key() {
let test_db = test_setup::only!(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15 ; exclude: CockroachDb);
let test_db = test_setup::only!(Postgres11, Postgres12, Postgres13, Postgres14, Postgres15, Postgres16 ; exclude: CockroachDb);
let (_, url_str) = tok(test_setup::postgres::create_postgres_database(
test_db.url(),
"inherited_table_detect_primary_key",
Expand Down

0 comments on commit e2ce1ac

Please sign in to comment.