Skip to content

chore(db): reset drizzle migrations with baseline#142

Merged
kryvosheyin merged 1 commit into
developfrom
chore/db-baseline-reset
Jan 14, 2026
Merged

chore(db): reset drizzle migrations with baseline#142
kryvosheyin merged 1 commit into
developfrom
chore/db-baseline-reset

Conversation

@kryvosheyin
Copy link
Copy Markdown
Collaborator

@kryvosheyin kryvosheyin commented Jan 14, 2026

This PR performs a controlled baseline reset of Drizzle migrations to resolve migration history corruption caused by parallel migration generation across multiple branches.

Production is treated as the single source of truth, and a new clean baseline migration is introduced to restore a linear, reliable migration history.

Background / Problem

Over time, multiple developers generated migrations in parallel, which resulted in:
• Multiple migration files sharing the same index (0013, 0014, 0015)
• Divergent local and production migration states
• Conflicts in drizzle/meta/_journal.json
• Inability to reliably bootstrap fresh environments
• Risk of silent schema drift

At this point, the migration history was no longer linear or trustworthy, and could not be safely repaired by reordering or deleting individual files.

What was done

  1. Production schema validated and corrected
    • email_verification_tokens table was found to be incorrect in prod
    • Table was empty and not relied upon
    • Dropped and recreated with the correct structure (token, user_id, expires_at, created_at)
  2. Baseline reset
    • All historical Drizzle migrations were archived
    • A new baseline migration (0000_*) was generated from the production schema
    • Baseline was validated by applying it to a clean local database
  3. Production stamped
    • Baseline migration hash was inserted into drizzle.__drizzle_migrations
    • Ensures production does not attempt to re-run baseline SQL
  4. Repository aligned
    • New migration history is clean and strictly linear
    • Schema files now match production exactly
    • Future migrations can proceed safely

Summary by CodeRabbit

  • Chores
    • Migrated database schema to PostgreSQL with UUID-based keys for improved scalability
    • Added support for orders, payments, and inventory management capabilities
    • Enabled multi-currency transactions (USD, UAH) and product variants (colors, sizes)
    • Enhanced authentication system with provider integration
    • Implemented point transaction tracking for rewards system

✏️ Tip: You can customize this high-level summary in your review settings.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 14, 2026

Deploy Preview for develop-devlovers ready!

Name Link
🔨 Latest commit d2e208a
🔍 Latest deploy log https://app.netlify.com/projects/develop-devlovers/deploys/69680af03490440008cdffe9
😎 Deploy Preview https://deploy-preview-142--develop-devlovers.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

This PR introduces database schema files including PostgreSQL migrations, metadata snapshots, and journal entries. It defines a comprehensive schema with UUID-based primary keys covering quiz management, user accounts, product catalog, inventory, orders, payments, and authentication tokens with numerous constraints and indexes for data integrity.

Changes

Cohort / File(s) Summary
Legacy Drizzle Migrations
frontend/db/legacy-migrations/drizzle_legacy/meta/0000_snapshot.json, frontend/db/legacy-migrations/drizzle_legacy/meta/_journal.json
New legacy PostgreSQL schema snapshot defining 12 tables (categories, questions, quiz-related, users, point_transactions) with composite keys and indexes. Associated journal file contains unresolved merge conflict in entries 13–15 with diverging tag/timestamp values.
Primary Drizzle Migration
frontend/drizzle/0000_dry_young_avengers.sql
Complete PostgreSQL schema migration introducing 6 enums (currency, inventory_move_type, inventory_status, order_status, payment_status, product_badge) and 23 tables covering quizzes, products, inventory, orders, payments, and auth tokens. Includes extensive CHECK constraints for business logic (non-negative prices, quantity validation, provider consistency) and comprehensive foreign-key relationships with cascading rules.
Drizzle Metadata & Journal
frontend/drizzle/meta/0000_snapshot.json, frontend/drizzle/meta/_journal.json
Snapshot metadata reflecting major schema evolution: migration from serial/integer to UUID-based primary keys, addition of category_translations and question_translations tables, expanded orders/products/users tables with new payment/inventory fields, new indexes across quiz/product/order entities. Journal entries reorganized with resolved historical sequence.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • AM1007
  • ViktorSvertoka
  • liudmylasovetovs

Poem

🐰 Hoppity-hop, migrations flow,
UUIDs sprout where serials used to grow,
Tables dance with foreign keys so tight,
Constraints ensure the data's right,
Our schema's grand, a rabbit's delight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the changeset: resetting Drizzle migrations to establish a clean baseline after migration history corruption.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a82de55 and d2e208a.

📒 Files selected for processing (44)
  • frontend/db/legacy-migrations/drizzle_legacy/0000_rich_magus.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0001_black_random.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0002_yielding_purple_man.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0003_handy_cammi.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0004_tough_ultron.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0005_furry_warstar.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0006_minor_units_money.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0007_add-payment-intent-id-to-orders.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0008_dizzy_james_howlett.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0009_p0_inventory_workflow_baseline.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0009_unknown_nico_minoru.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0010_parallel_princess_powerful.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0011_add_orders_sweep_claim_index.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0012_inventory_moves_product_fk_restrict.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0013_add_internal_job_state.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0013_brown_gamora.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0013_low_roughhouse.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0014_add-stripe-events-processed-at.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0014_dapper_kang.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0014_steep_kabuki.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0015_dear_legion.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0015_glamorous_eternity.sql
  • frontend/db/legacy-migrations/drizzle_legacy/0015_warm_dexter_bennett.sql
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0000_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0001_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0002_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0003_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0004_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0005_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0006_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0007_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0008_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0009_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0010_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0012_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0013_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0014_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/0015_snapshot.json
  • frontend/db/legacy-migrations/drizzle_legacy/meta/_journal.json
  • frontend/db/legacy-migrations/drizzle_legacy/relations.ts
  • frontend/db/legacy-migrations/drizzle_legacy/schema.ts
  • frontend/drizzle/0000_dry_young_avengers.sql
  • frontend/drizzle/meta/0000_snapshot.json
  • frontend/drizzle/meta/_journal.json
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-12-30T16:01:02.523Z
Learnt from: kryvosheyin
Repo: DevLoversTeam/devlovers.net PR: 88
File: frontend/drizzle/schema.ts:153-153
Timestamp: 2025-12-30T16:01:02.523Z
Learning: The file frontend/drizzle/schema.ts is a legacy file not used by Drizzle or the runtime. The canonical schemas live in frontend/db/schema/* as configured in drizzle-config.ts, and that's what migrations and runtime use.

Applied to files:

  • frontend/db/legacy-migrations/drizzle_legacy/meta/0000_snapshot.json
  • frontend/drizzle/0000_dry_young_avengers.sql
🪛 Biome (2.1.2)
frontend/db/legacy-migrations/drizzle_legacy/meta/_journal.json

[error] 98-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: expected , but instead found HEAD

Remove HEAD

(parse)


[error] 100-100: expected , but instead found "when"

Remove "when"

(parse)


[error] 100-100: expected , but instead found :

Remove :

(parse)


[error] 100-100: expected , but instead found 1768162667947

Remove 1768162667947

(parse)


[error] 101-101: expected , but instead found :

Remove :

(parse)


[error] 101-101: expected , but instead found "0013_brown_gamora"

Remove "0013_brown_gamora"

(parse)


[error] 101-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 103-103: expected , but instead found "when"

Remove "when"

(parse)


[error] 103-103: expected , but instead found :

Remove :

(parse)


[error] 103-103: expected , but instead found 1767697281389

Remove 1767697281389

(parse)


[error] 104-104: expected , but instead found :

Remove :

(parse)


[error] 104-104: expected , but instead found "0013_low_roughhouse"

Remove "0013_low_roughhouse"

(parse)


[error] 105-105: expected , but instead found :

Remove :

(parse)


[error] 105-105: expected , but instead found true

Remove true

(parse)


[error] 106-106: expected , but instead found }

Remove }

(parse)


[error] 106-106: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 107-113: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 113-113: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 114-118: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 118-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: String values must be double quoted.

(parse)


[error] 119-119: unexpected character (

(parse)


[error] 119-119: String values must be double quoted.

(parse)


[error] 119-119: unexpected character (

(parse)


[error] 119-119: String values must be double quoted.

(parse)


[error] 119-119: unexpected character )

(parse)


[error] 119-119: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 119-119: unexpected character )

(parse)


[error] 120-120: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 120-120: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 120-120: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 121-121: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 122-128: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 129-130: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

🔇 Additional comments (7)
frontend/db/legacy-migrations/drizzle_legacy/meta/0000_snapshot.json (1)

1-947: LGTM - Legacy migration snapshot properly archived.

This snapshot correctly preserves the historical schema state for reference. The structure is valid and maintains the pre-baseline migration history as documented in the PR objectives.

frontend/drizzle/meta/_journal.json (1)

1-13: LGTM - Clean baseline migration journal.

The journal correctly reflects a fresh linear migration history with a single baseline entry, which aligns with the PR's objective to restore a reliable migration state.

frontend/drizzle/0000_dry_young_avengers.sql (4)

1-6: Well-structured ENUM types for domain modeling.

The enum definitions provide clear domain boundaries for currency, inventory operations, order lifecycle, and payment states.


171-177: Excellent use of CHECK constraints for data integrity.

The mirror consistency constraints (order_items_line_total_consistent, order_items_unit_price_mirror_consistent, etc.) ensure the integer-cents and decimal columns stay synchronized at the database level, preventing data corruption from application bugs.


275-287: Verify intentional omission of foreign key on token tables.

Both email_verification_tokens and password_reset_tokens reference user_id but lack a foreign key constraint to users.id. This is often intentional for auth tokens (allows independent cleanup, doesn't block user deletion), but worth confirming given the PR mentions these tables were recreated.


289-334: LGTM - Foreign keys and indexes well-defined.

The foreign key behaviors (cascade, restrict, set null) are appropriately chosen for each relationship, and indexes support expected query patterns for lookups and filtering.

frontend/drizzle/meta/0000_snapshot.json (1)

1-2441: LGTM - Baseline snapshot consistent with SQL migration.

The snapshot accurately reflects the schema defined in 0000_dry_young_avengers.sql, including all tables, enums, constraints, indexes, and foreign key relationships.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +96 to +129
{
"idx": 13,
"version": "7",
<<<<<<< HEAD
"when": 1768162667947,
"tag": "0013_brown_gamora",
=======
"when": 1767697281389,
"tag": "0013_low_roughhouse",
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1768045270184,
"tag": "0014_dapper_kang",
"breakpoints": true
},
{
"idx": 15,
"version": "7",
"when": 1768166276337,
"tag": "0015_glamorous_eternity",
>>>>>>> b30415e (feat(auth): add email verification, password reset, and improved auth UX)
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1768304911639,
"tag": "0014_steep_kabuki",
"breakpoints": true
}
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Unresolved merge conflict renders file invalid.

This file contains unresolved Git merge conflict markers (<<<<<<< HEAD, =======, >>>>>>> b30415e), making it invalid JSON. This will cause Drizzle to fail when parsing migration metadata.

The conflict shows two divergent histories:

  • HEAD: idx 13 → 0013_brown_gamora, then 0014_steep_kabuki
  • Other branch: idx 13-15 → 0013_low_roughhouse, 0014_dapper_kang, 0015_glamorous_eternity

You need to resolve this conflict by choosing the correct migration history or, given this PR's baseline reset objective, potentially removing the conflicting entries entirely since this is archived legacy metadata.

🔧 Suggested resolution (if keeping as archive)

If this file should preserve pre-baseline history, resolve by keeping one consistent sequence:

    {
      "idx": 13,
      "version": "7",
-<<<<<<< HEAD
-      "when": 1768162667947,
-      "tag": "0013_brown_gamora",
-=======
      "when": 1767697281389,
      "tag": "0013_low_roughhouse",
      "breakpoints": true
    },
    {
      "idx": 14,
      "version": "7",
      "when": 1768045270184,
      "tag": "0014_dapper_kang",
      "breakpoints": true
    },
    {
      "idx": 15,
      "version": "7",
      "when": 1768166276337,
      "tag": "0015_glamorous_eternity",
->>>>>>> b30415e (feat(auth): add email verification, password reset, and improved auth UX)
-      "breakpoints": true
-    },
-    {
-      "idx": 14,
-      "version": "7",
-      "when": 1768304911639,
-      "tag": "0014_steep_kabuki",
      "breakpoints": true
    }
  ]
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"idx": 13,
"version": "7",
<<<<<<< HEAD
"when": 1768162667947,
"tag": "0013_brown_gamora",
=======
"when": 1767697281389,
"tag": "0013_low_roughhouse",
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1768045270184,
"tag": "0014_dapper_kang",
"breakpoints": true
},
{
"idx": 15,
"version": "7",
"when": 1768166276337,
"tag": "0015_glamorous_eternity",
>>>>>>> b30415e (feat(auth): add email verification, password reset, and improved auth UX)
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1768304911639,
"tag": "0014_steep_kabuki",
"breakpoints": true
}
]
{
"idx": 13,
"version": "7",
"when": 1767697281389,
"tag": "0013_low_roughhouse",
"breakpoints": true
},
{
"idx": 14,
"version": "7",
"when": 1768045270184,
"tag": "0014_dapper_kang",
"breakpoints": true
},
{
"idx": 15,
"version": "7",
"when": 1768166276337,
"tag": "0015_glamorous_eternity",
"breakpoints": true
}
]
🧰 Tools
🪛 Biome (2.1.2)

[error] 98-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: unexpected character <

(parse)


[error] 99-99: expected , but instead found HEAD

Remove HEAD

(parse)


[error] 100-100: expected , but instead found "when"

Remove "when"

(parse)


[error] 100-100: expected , but instead found :

Remove :

(parse)


[error] 100-100: expected , but instead found 1768162667947

Remove 1768162667947

(parse)


[error] 101-101: expected , but instead found :

Remove :

(parse)


[error] 101-101: expected , but instead found "0013_brown_gamora"

Remove "0013_brown_gamora"

(parse)


[error] 101-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 102-102: unexpected character =

(parse)


[error] 103-103: expected , but instead found "when"

Remove "when"

(parse)


[error] 103-103: expected , but instead found :

Remove :

(parse)


[error] 103-103: expected , but instead found 1767697281389

Remove 1767697281389

(parse)


[error] 104-104: expected , but instead found :

Remove :

(parse)


[error] 104-104: expected , but instead found "0013_low_roughhouse"

Remove "0013_low_roughhouse"

(parse)


[error] 105-105: expected , but instead found :

Remove :

(parse)


[error] 105-105: expected , but instead found true

Remove true

(parse)


[error] 106-106: expected , but instead found }

Remove }

(parse)


[error] 106-106: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 107-113: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 113-113: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 114-118: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 118-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: unexpected character >

(parse)


[error] 119-119: String values must be double quoted.

(parse)


[error] 119-119: unexpected character (

(parse)


[error] 119-119: String values must be double quoted.

(parse)


[error] 119-119: unexpected character (

(parse)


[error] 119-119: String values must be double quoted.

(parse)


[error] 119-119: unexpected character )

(parse)


[error] 119-119: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 119-119: unexpected character )

(parse)


[error] 120-120: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 120-120: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 120-120: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 121-121: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 122-128: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

@kryvosheyin kryvosheyin merged commit bb46d8c into develop Jan 14, 2026
9 checks passed
@kryvosheyin kryvosheyin deleted the chore/db-baseline-reset branch January 14, 2026 21:42
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.

1 participant