question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Migrations

See original GitHub issue

Just like replace is doing it for Data, we could add an utility function which looks at first if a table exists, if not create it, and if the table exists also checks if fields|columns are missing, adds them in a non-destructive fashion.

I’ve already made an Table Creator that i could PR(if wanted)

Ex.:

checkTableExists('session').then(...).catch(() => {
           createTable("session", [
                new BaseField('id').isUnique().setType("VARCHAR(256)"),
                new BaseField('created_at').setType('BIGNUMBER')
            ])
        })

It doesn’t yet support checking for fields missing. Though creating a table would be a useful addition i think.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rahmanfadhilcommented, Jun 14, 2020

Awesome! I’m very glad you like it!

We should take another look at some of the functions and let them throw if default case happens:

That’s a pretty easy thing to fix. And the tests will fail anyway since we have a special test case for this. So, everything is good.

https://github.com/rahmanfadhil/cotton/blob/5828520c05d5fe4edbe717cceca3e4df4f82f174/src/migrations/migration_test.ts#L5-L13

Maybe later we could even make an SQL Exporter/Importer(that would be useful for the moment a project wants to branch out to a bigger type of database sqlite => mysqldb or mariadb), i think i got something like that already somewhere for JS.

I’m not sure if anyone needs to export/import their database programmatically. Maybe we can provide a CLI for it? 🤔

Anyway, I’m really excited to have some kind of database seeder and factory to populate the database with realistic dummy data for development and testing purposes.

Lastly, I’m going to remove the old migration code in src/table.ts, because everything is already moved to src/migrations.

I will keep this issue open until this feature is released and merged into the master branch. So, if you have any ideas or suggestions, I’m more than happy to discuss about it. Thanks!

0reactions
rahmanfadhilcommented, Jul 28, 2020

This feature is now merged with master 🎉

Checkout the docs for more info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Database Migrations | FeatureFlags
Use feature flags to safely migrate or update databases. There comes a time in every developer's life when you realize you need to...
Read more >
Database Migrations with Feature Flags - Split Software
In this post, we are talking about database migrations in the context of updating schemas ... Use Feature Flags to Migrate Your Schemas....
Read more >
Using feature flags to mitigate risk in infrastructure migrations
This guide explains how you can use feature flags to mitigate risks associated with infrastructure migrations.
Read more >
Feature toggles and database migrations (Part 3)
Part 3 of this series focusses specifically on using toggles when migrating databases.
Read more >
Migrations Overview - EF Core | Microsoft Learn
The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found