From 3904c7c78178904a59f9cd56e27c62698325cab7 Mon Sep 17 00:00:00 2001 From: Taylor Bantle Date: Tue, 1 Oct 2024 16:59:04 -0700 Subject: [PATCH] Diff tests for changes in multiple schemas --- .../node/workbenchTests/diffs.js | 260 ++++++++++++++++-- 1 file changed, 242 insertions(+), 18 deletions(-) diff --git a/testing/postgres-client-tests/node/workbenchTests/diffs.js b/testing/postgres-client-tests/node/workbenchTests/diffs.js index 85b9a3c6af..5662278277 100644 --- a/testing/postgres-client-tests/node/workbenchTests/diffs.js +++ b/testing/postgres-client-tests/node/workbenchTests/diffs.js @@ -3,6 +3,8 @@ import { doltDiffStatFields, doltDiffSummaryFields, doltSchemaDiffFields, + doltStatusFields, + pgTablesFields, } from "../fields.js"; import { diffRowsMatcher, patchRowsMatcher } from "./matchers.js"; @@ -28,14 +30,61 @@ export const diffTests = [ }, }, { - q: "SELECT * FROM dolt_diff_summary('HEAD', 'WORKING')", // TODO: Prepared not working + q: `CREATE SCHEMA anotherschema;`, + res: { + command: "CREATE", + rowCount: null, + oid: null, + rows: [], + fields: [], + }, + }, + { + q: `create table anotherschema.testanother (pk int, "value" int, primary key(pk));`, + res: { + command: "CREATE", + rowCount: null, + oid: null, + rows: [], + fields: [], + }, + }, + { + q: "INSERT INTO anotherschema.testanother VALUES (1, 2)", + res: { + command: "INSERT", + rowCount: 1, + oid: 0, + rows: [], + fields: [], + }, + }, + { + q: `SELECT * FROM dolt_status ORDER BY table_name;`, res: { command: "SELECT", - rowCount: 3, + rowCount: 5, + oid: null, + rows: [ + // TODO: Should we distinguish which table belongs to which schema? + { table_name: "anotherschema", staged: 0, status: "new schema" }, + { table_name: "dolt_schemas", staged: 0, status: "new table" }, + { table_name: "test", staged: 0, status: "modified" }, + { table_name: "test_info", staged: 0, status: "deleted" }, + { table_name: "testanother", staged: 0, status: "new table" }, + ], + fields: doltStatusFields, + }, + }, + { + q: "SELECT * FROM dolt_diff_summary('HEAD', 'WORKING') ORDER BY to_table_name", // TODO: Prepared not working + res: { + command: "SELECT", + rowCount: 4, oid: null, rows: [ { - from_table_name: "test_info", + from_table_name: "test_info", // public.test_info to_table_name: "", diff_type: "dropped", data_change: 1, @@ -43,18 +92,25 @@ export const diffTests = [ }, { from_table_name: "", - to_table_name: "dolt_schemas", + to_table_name: "dolt_schemas", // public.dolt_schemas diff_type: "added", data_change: 1, schema_change: 1, }, { - from_table_name: "test", - to_table_name: "test", + from_table_name: "test", // public.test + to_table_name: "test", // public.test diff_type: "modified", data_change: 1, schema_change: 0, }, + { + from_table_name: "", + to_table_name: "testanother", // anotherschema.testanother + diff_type: "added", + data_change: 1, + schema_change: 1, + }, ], fields: doltDiffSummaryFields, }, @@ -78,14 +134,33 @@ export const diffTests = [ }, }, { - q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING')", + // TODO: What if a table with same name but different schema exists in different schema? + q: "SELECT * FROM dolt_diff_summary('HEAD', 'WORKING', 'testanother')", res: { command: "SELECT", - rowCount: 3, + rowCount: 1, oid: null, rows: [ { - table_name: "dolt_schemas", + from_table_name: "", + to_table_name: "testanother", // anotherschema.testanother + diff_type: "added", + data_change: 1, + schema_change: 1, + }, + ], + fields: doltDiffSummaryFields, + }, + }, + { + q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING') ORDER BY table_name", + res: { + command: "SELECT", + rowCount: 4, + oid: null, + rows: [ + { + table_name: "dolt_schemas", // public.dolt_schemas rows_unmodified: "0", rows_added: "1", rows_deleted: "0", @@ -99,7 +174,7 @@ export const diffTests = [ new_cell_count: "5", }, { - table_name: "test", + table_name: "test", // public.test rows_unmodified: "2", rows_added: "0", rows_deleted: "0", @@ -113,7 +188,7 @@ export const diffTests = [ new_cell_count: "6", }, { - table_name: "test_info", + table_name: "test_info", // public.test_info rows_unmodified: "0", rows_added: "0", rows_deleted: "1", @@ -126,6 +201,20 @@ export const diffTests = [ old_cell_count: "3", new_cell_count: "0", }, + { + table_name: "testanother", // anotherschema.testanother + rows_unmodified: "0", + rows_added: "1", + rows_deleted: "0", + rows_modified: "0", + cells_added: "2", + cells_deleted: "0", + cells_modified: "0", + old_row_count: "0", + new_row_count: "1", + old_cell_count: "0", + new_cell_count: "2", + }, ], fields: doltDiffStatFields, }, @@ -138,7 +227,7 @@ export const diffTests = [ oid: null, rows: [ { - table_name: "test_info", + table_name: "test_info", // public.test_info rows_unmodified: "0", rows_added: "0", rows_deleted: "1", @@ -155,6 +244,31 @@ export const diffTests = [ fields: doltDiffStatFields, }, }, + { + q: "SELECT * FROM dolt_diff_stat('HEAD', 'WORKING', 'testanother')", + res: { + command: "SELECT", + rowCount: 1, + oid: null, + rows: [ + { + table_name: "testanother", // anotherschema.testanother + rows_unmodified: "0", + rows_added: "1", + rows_deleted: "0", + rows_modified: "0", + cells_added: "2", + cells_deleted: "0", + cells_modified: "0", + old_row_count: "0", + new_row_count: "1", + old_cell_count: "0", + new_cell_count: "2", + }, + ], + fields: doltDiffStatFields, + }, + }, { q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'test') ORDER BY to_pk ASC, from_pk ASC LIMIT 10 OFFSET 0", res: { @@ -203,6 +317,32 @@ export const diffTests = [ }, matcher: diffRowsMatcher, }, + { + skip: true, // TODO: error: table not found: testanother + q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'testanother') ORDER BY to_id ASC, from_id ASC LIMIT 10 OFFSET 0", + res: { + command: "SELECT", + rowCount: 1, + oid: null, + rows: [ + { + to_id: null, + to_info: null, + to_test_pk: null, + to_commit: "WORKING", + to_commit_date: "2023-03-09T07:53:48.614Z", + from_id: 1, + from_info: "info about test pk 0", + from_test_pk: 0, + from_commit: "HEAD", + from_commit_date: "2023-03-09T07:53:48.284Z", + diff_type: "added", + }, + ], + fields: [], + }, + matcher: diffRowsMatcher, + }, { q: "SELECT * FROM DOLT_DIFF('HEAD', 'WORKING', 'dolt_schemas') ORDER BY to_name ASC, from_name ASC LIMIT 10 OFFSET 0", res: { @@ -234,10 +374,11 @@ export const diffTests = [ matcher: diffRowsMatcher, }, { + skip: true, // TODO: Order is not consistent q: "SELECT * FROM DOLT_PATCH('HEAD', 'WORKING') WHERE diff_type = 'schema'", res: { command: "SELECT", - rowCount: 2, + rowCount: 3, oid: null, rows: [ { @@ -248,8 +389,22 @@ export const diffTests = [ diff_type: "schema", statement: "DROP TABLE `test_info`;", }, + // TODO: Should `CREATE SCHEMA` statement be included here? { statement_order: "2", + from_commit_hash: "r6g8g61k89dpgb3cuks70jfnavr6b1q0", + to_commit_hash: "WORKING", + table_name: "testanother", + diff_type: "schema", + statement: + "CREATE TABLE `testanother` (\n" + + " `pk` integer NOT NULL,\n" + + " `value` integer,\n" + + " PRIMARY KEY (`pk`)\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", + }, + { + statement_order: "4", // TODO: Why is this 4? from_commit_hash: "", to_commit_hash: "WORKING", table_name: "dolt_schemas", @@ -289,10 +444,10 @@ export const diffTests = [ matcher: patchRowsMatcher, }, { - q: "SELECT * FROM DOLT_SCHEMA_DIFF('HEAD', 'WORKING')", + q: "SELECT * FROM DOLT_SCHEMA_DIFF('HEAD', 'WORKING') ORDER BY to_table_name", res: { command: "SELECT", - rowCount: 2, + rowCount: 3, oid: null, rows: [ { @@ -323,6 +478,17 @@ export const diffTests = [ " PRIMARY KEY (`type`,`name`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", }, + { + from_table_name: "", + to_table_name: "testanother", + from_create_statement: "", + to_create_statement: + "CREATE TABLE `testanother` (\n" + + " `pk` integer NOT NULL,\n" + + " `value` integer,\n" + + " PRIMARY KEY (`pk`)\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", + }, ], fields: doltSchemaDiffFields, }, @@ -352,6 +518,28 @@ export const diffTests = [ fields: doltSchemaDiffFields, }, }, + { + q: "SELECT * FROM DOLT_SCHEMA_DIFF('HEAD', 'WORKING', 'testanother')", + res: { + command: "SELECT", + rowCount: 1, + oid: null, + rows: [ + { + from_table_name: "", + to_table_name: "testanother", + from_create_statement: "", + to_create_statement: + "CREATE TABLE `testanother` (\n" + + " `pk` integer NOT NULL,\n" + + " `value` integer,\n" + + " PRIMARY KEY (`pk`)\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", + }, + ], + fields: doltSchemaDiffFields, + }, + }, { q: `SELECT DOLT_COMMIT('-A', '-m', $1::text)`, p: ["Make some changes on branch"], @@ -369,7 +557,7 @@ export const diffTests = [ q: "SELECT * FROM dolt_diff_summary('main...HEAD')", res: { command: "SELECT", - rowCount: 3, + rowCount: 4, oid: null, rows: [ { @@ -379,6 +567,13 @@ export const diffTests = [ data_change: 1, schema_change: 1, }, + { + from_table_name: "", + to_table_name: "testanother", + diff_type: "added", + data_change: 1, + schema_change: 1, + }, { from_table_name: "", to_table_name: "dolt_schemas", @@ -419,7 +614,7 @@ export const diffTests = [ q: "SELECT * FROM dolt_diff_stat('main...HEAD')", res: { command: "SELECT", - rowCount: 3, + rowCount: 4, oid: null, rows: [ { @@ -436,6 +631,20 @@ export const diffTests = [ old_cell_count: "0", new_cell_count: "5", }, + { + table_name: "testanother", + rows_unmodified: "0", + rows_added: "1", + rows_deleted: "0", + rows_modified: "0", + cells_added: "2", + cells_deleted: "0", + cells_modified: "0", + old_row_count: "0", + new_row_count: "1", + old_cell_count: "0", + new_cell_count: "2", + }, { table_name: "test", rows_unmodified: "2", @@ -494,10 +703,11 @@ export const diffTests = [ }, }, { + skip: true, // TODO: Order not consistent q: "SELECT * FROM DOLT_PATCH('main...HEAD') WHERE diff_type = 'schema'", res: { command: "SELECT", - rowCount: 3, + rowCount: 4, oid: null, rows: [ { @@ -512,6 +722,20 @@ export const diffTests = [ statement_order: "2", from_commit_hash: "", to_commit_hash: "", + table_name: "testanother", + diff_type: "schema", + statement: + "CREATE TABLE `testanother` (\n" + + " `pk` integer NOT NULL,\n" + + " `value` integer,\n" + + " PRIMARY KEY (`pk`)\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;", + }, + // TODO: `CREATE SCHEMA` here? + { + statement_order: "4", // TODO: why + from_commit_hash: "", + to_commit_hash: "", table_name: "dolt_schemas", diff_type: "schema", statement: