How to Normalize Database using Drizzle?
I previously have made my Order Table to only support one service/line item back then (based on the business logic back then). Now, I need to normalize my database, so that it supports multiple services/line items in a single order. I have tried to write the migration file but it's not running.
Solution:Jump to solution
Node can’t execute ts file. You can try to run your script with tsx.
npx tsx path/to/your/file.ts...
5 Replies
Here is my table
and this is what I wrote for the migration
This is the error that I got. I tried to use
require
instead but it's not working as well.
Solution
Node can’t execute ts file. You can try to run your script with tsx.
npx tsx path/to/your/file.ts
@Raphaël M (@rphlmr) ⚡ thank you! it's working now, but I need to use dotenv on my DB config to read the env file.
I have another question just for my improvements. Am I doing the database normalization the right way as it should be? Are people in the industry doing it this way as well? Or there should be a better way to tackle this kind of problem?
I'm currently saving the migration script as
/db/migration/YYYYMMDD_migrate_orders_to_new_schema.ts
and I will be commiting the script to git.Oh you can also do something like that:
dotenv -e .env -- npx xxx
(with "dotenv-cli" in dev dep)
It always depends, but from experience, I do the same thing as new_order and order_line_item. Most of the time, I use arrays instead of single values too for things that can evolve to ‘oh, now we can have more than one thing here’ (so, db normalization))
it is more code at first, but less pain in the future.
I am far from being a database expert, and it took me so much time to decide on a design 😂
I'm currently saving the migration script as /db/migration/YYYYMMDD_migrate_orders_to_new_schema.ts and I will be commiting the script to git.This is the way, a project I work on for years now has many of these scripts
thank you for your insights! at least i think I'm on the right track 😄