Skip to content

Add: Dashboard db migrations & tooling #6

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

Merged
merged 10 commits into from
Mar 13, 2025

Conversation

ben-fornefeld
Copy link
Member

this pr moves dashboard specific migrations inside this repo. also it adds tooling to work with db migrations.

@ben-fornefeld ben-fornefeld added enhancement New feature or request feature labels Mar 11, 2025
@ben-fornefeld ben-fornefeld self-assigned this Mar 11, 2025
Copy link

linear bot commented Mar 11, 2025

Copy link

vercel bot commented Mar 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 13, 2025 3:19pm

Copy link
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

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

Either delete the apply migration script or add tracking

Copy link
Member

@jakubno jakubno left a comment

Choose a reason for hiding this comment

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

In readme you are missing bun as a prerequisite, also it needs to be 1.2 + because of SQL. I guess npm is not supported anymore.

Not sure if we want to replicate migration logic here, like splitting sql statements etc, why are we solving already solved problem.

AI is really good, but not checking the code afterwards or testing it ngmi..

async function ensureMigrationsTable() {
try {
await db(`
CREATE TABLE IF NOT EXISTS public._migrations (
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CREATE TABLE IF NOT EXISTS public._migrations (
CREATE TABLE IF NOT EXISTS public._dahboard_migrations (

Comment on lines 38 to 40
await db(`
GRANT ALL ON public._migrations TO supabase_admin;
`)
Copy link
Member

Choose a reason for hiding this comment

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

could you explain why you added?

*/
async function ensureMigrationsTable() {
try {
await db(`
Copy link
Member

Choose a reason for hiding this comment

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

this isn't working because correct syntax is

Suggested change
await db(`
await db`

content: string
): Promise<{ applied: boolean; checksumMatch: boolean }> {
// Query to get the existing migration record
const result = await db.unsafe(
Copy link
Member

Choose a reason for hiding this comment

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

there's no need to this to be unsafe

): Promise<void> {
// Convert checksum to string to avoid bigint overflow
const checksum = String(Bun.hash(content))
await db.unsafe(
Copy link
Member

Choose a reason for hiding this comment

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

no need to be unsafe

README.md Outdated
### Migration Safety

The system includes several safety features:
- Migrations are applied in a transaction (all-or-nothing)
Copy link
Member

Choose a reason for hiding this comment

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

not true!

@ben-fornefeld
Copy link
Member Author

ben-fornefeld commented Mar 12, 2025

In readme you are missing bun as a prerequisite, also it needs to be 1.2 + because of SQL. I guess npm is not supported anymore.

i knew all of this. wanted to try the bun sql package. not the best decision for public use indeed.

Not sure if we want to replicate migration logic here, like splitting sql statements etc, why are we solving already solved problem.

fair.

AI is really good, but not checking the code afterwards or testing it ngmi..

code was of course checked & tested multiple times. i did bad decisions while doing so is a better way to put it.

Copy link
Member

Choose a reason for hiding this comment

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

can we just delete it for now? We can add it later in separate pr and update the table manually

Co-authored-by: Jakub Novák <kubus.novak@gmail.com>
@jakubno
Copy link
Member

jakubno commented Mar 13, 2025

code was of course checked & tested multiple times. i did bad decisions while doing so is a better way to put it.

E.g. migrations weren't tested, at least not without some already existing tables, because it was failing as I mentioned in PR

@ben-fornefeld
Copy link
Member Author

code was of course checked & tested multiple times. i did bad decisions while doing so is a better way to put it.

E.g. migrations weren't tested, at least not without some already existing tables, because it was failing as I mentioned in PR

i tested it multiple times with multiple scenarios. maybe there was some edge case i did not caught. just want to mention that i of course test the code i write and not just push blindly on purpose.

@jakubno
Copy link
Member

jakubno commented Mar 13, 2025

I applied it to my database, I think going from clean state isn't an edge case

@jakubno jakubno merged commit d477a90 into main Mar 13, 2025
3 checks passed
@jakubno jakubno deleted the set-up-dashboard-db-migrations-e2b-1753 branch March 13, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants