Skip to content

refactor(store): enforce NOT NULL on nullable text columns - #13

Merged
0dillon merged 1 commit into
0dillon:mainfrom
ogundeleoluwaferanmi35:enforce-not-null-text-columns
Aug 14, 2026
Merged

refactor(store): enforce NOT NULL on nullable text columns#13
0dillon merged 1 commit into
0dillon:mainfrom
ogundeleoluwaferanmi35:enforce-not-null-text-columns

Conversation

@ogundeleoluwaferanmi35

Copy link
Copy Markdown
Contributor

Summary

Three TEXT columns in the PostgreSQL schema were nullable:

  • challenges.client_domain
  • sessions.memo
  • sessions.client_domain

For consistency and stricter data integrity they now use NOT NULL DEFAULT '', so the absence of a value is stored as an empty string rather than NULL.

Changes

  • Added migration 000002_not_null_text_columns that backfills existing NULL values with '' before setting DEFAULT '' and NOT NULL on each column, plus a matching down migration.
  • Updated internal/store/postgres.go to insert empty strings directly (removed the nullable helper) and to scan client_domain straight into a string instead of through a *string.
  • Updated TestMigrationsAreEmbedded to expect the new migration files and assert the SET NOT NULL alters are present.

Verification

  • gofmt, go vet, go build, and go test ./... pass.
  • Postgres integration tests pass: go test -tags postgres_integration ./internal/store/.
  • Confirmed via information_schema that all three columns are NOT NULL with default '', and the down migration applies cleanly.

Closes #3

Make challenges.client_domain, sessions.memo, and sessions.client_domain
NOT NULL DEFAULT '', storing the absence of a value as an empty string
rather than NULL. Adds a golang-migrate migration that backfills existing
NULLs before tightening the columns, and updates the store to insert and
read strings directly instead of through a nullable helper.

Closes 0dillon#3
@ogundeleoluwaferanmi35
ogundeleoluwaferanmi35 force-pushed the enforce-not-null-text-columns branch from d1b4fe7 to 5174a3b Compare August 14, 2026 01:20
@0dillon
0dillon merged commit 4aedf41 into 0dillon:main Aug 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(store): enforce NOT NULL on nullable text columns

2 participants