Skip to content

Commit e791e30

Browse files
committed
fix(pgsql/test): use nullable columns in createTable, fix Test_DB_TableFields
createTable uses NULL columns for non-PK fields to support partial inserts in ported tests (OmitEmpty/Hook/Concurrent/Transaction). Update Test_DB_TableFields expectations to match nullable schema.
1 parent 702719b commit e791e30

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

contrib/drivers/pgsql/pgsql_z_unit_core_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ func Test_Core_ClearTableFields(t *testing.T) {
151151
gtest.C(t, func(t *gtest.T) {
152152
fields, err := db.TableFields(ctx, table)
153153
t.AssertNil(err)
154-
// PgSQL baseline table has 10 columns:
155-
// id, passport, password, nickname, create_time, create_date,
154+
// PgSQL baseline table has 9 columns:
155+
// id, passport, password, nickname, create_time,
156156
// favorite_movie, favorite_music, numeric_values, decimal_values.
157-
t.Assert(len(fields), 10)
157+
t.Assert(len(fields), 9)
158158
})
159159
gtest.C(t, func(t *gtest.T) {
160160
err := db.GetCore().ClearTableFields(ctx, table)

contrib/drivers/pgsql/pgsql_z_unit_db_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ func Test_DB_TableFields(t *testing.T) {
324324
// []string: Index Type Null Key Default Comment
325325
// id is bigserial so the default is a pgsql function
326326
"id": {0, "int8(64)", false, "pri", fmt.Sprintf("nextval('%s_id_seq'::regclass)", table), ""},
327-
"passport": {1, "varchar(45)", false, "", nil, ""},
328-
"password": {2, "varchar(32)", false, "", nil, ""},
329-
"nickname": {3, "varchar(45)", false, "", nil, ""},
330-
"create_time": {4, "timestamp", false, "", nil, ""},
327+
"passport": {1, "varchar(45)", true, "", nil, ""},
328+
"password": {2, "varchar(32)", true, "", nil, ""},
329+
"nickname": {3, "varchar(45)", true, "", nil, ""},
330+
"create_time": {4, "timestamp", true, "", nil, ""},
331331
}
332332

333333
res, err := db.TableFields(ctx, table)

contrib/drivers/pgsql/pgsql_z_unit_init_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,15 @@ func createTableWithDb(db gdb.DB, table ...string) (name string) {
7777

7878
dropTableWithDb(db, name)
7979

80-
// Schema aligned with MySQL/MariaDB baseline: passport/password/nickname/create_time are nullable.
81-
// This allows ported tests (OmitEmpty/OmitNil/etc.) to exercise partial inserts without failing
82-
// on NOT NULL constraints that don't exist in the MySQL baseline.
80+
// Non-PK columns are nullable to allow partial inserts in ported tests
81+
// (OmitEmpty/OmitNil/Hook/Concurrent/Transaction tests).
8382
if _, err := db.Exec(ctx, fmt.Sprintf(`
8483
CREATE TABLE %s (
8584
id bigserial NOT NULL,
8685
passport varchar(45) NULL,
8786
password varchar(32) NULL,
8887
nickname varchar(45) NULL,
8988
create_time timestamp NULL,
90-
create_date date NULL,
9189
favorite_movie varchar[],
9290
favorite_music text[],
9391
numeric_values numeric[],

0 commit comments

Comments
 (0)