Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate schema definition and migrations to Drizzle #433

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

poteboy
Copy link
Collaborator

@poteboy poteboy commented Jan 20, 2025

This PR migrates our schema management from Zero to Drizzle as Drizzle now supports many-to-many relationships. I'm also separating database initialization from schema management, where Docker only handles database creation while Drizzle manages schema and migrations.

Please review the schema mappings carefully, as there might be subtle differences in how relationships are defined between Zero and Drizzle. @natew

Changes

  • Migrated schema definitions from Zero to Drizzle
  • Removed table creation from seed.sql, keeping only database creation in init.sql
  • Added seeding process to run after migrations
  • Fixed bulk insert in reaction seeder
  • Updated development workflow to handle migrations properly

Technical Details

  • Database creation is now handled by init.sql in Docker
  • Schema definitions moved to Drizzle's from zero's
  • Seeding process runs after migration to ensure schema exists

Next Steps

Related Issues

Copy link

railway-app bot commented Jan 20, 2025

🚅 Deployed to the one-pr-433 environment in onestack.dev

Service Status Web Updated (UTC)
one ✅ Success (View Logs) Web Jan 23, 2025 at 9:56 am

@@ -5,15 +5,15 @@ services:
user: postgres
restart: always
healthcheck:
test: 'pg_isready -U user --dbname=postgres'
test: 'pg_isready -U user --dbname=onechat'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There was a diff between the database name in the .env you provided earlier and the actual setup, so I adjusted it to match the environment variables. @natew

Choose a reason for hiding this comment

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

Since you are creating a Database onechat inside init.sql, i dont think you intended to make the onechat as an default DB. Sticking to postgres as default one is correct (or at least should have different name than onechat if you want to create onechat inside init.sql)

Copy link
Collaborator

Choose a reason for hiding this comment

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

makes sense @cermakondrej

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah you are right, thank you! @cermakondrej

)
VALUES ${valueStrings.join(',')}
`,
values: values.flatMap((v) => [v.id, v.value, v.keyword, v.created_at, v.updated_at]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can also define the seed data here in TypeScript with Drizzle, which was previously defined in the raw seed.sql.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i had some of that work in the old pr

@natew
Copy link
Collaborator

natew commented Jan 22, 2025

@poteboy lets update this and see if it works with the new drizzle zero so we can merge

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.

3 participants