Need help?
<- Back

Comments (51)

  • lun3x
    Tried it out now with SQLite to see what it does with difficult migrations, like adding a foreign key constraint to an existing table. Looks like it just generates invalid migrations, eg:`ALTER TABLE books ADD CONSTRAINT fk_books_author FOREIGN KEY (author_id) REFERENCES authors (id)`Which is not valid in SQLite (https://www.sqlite.org/lang_altertable.html)
  • tianzhou
    If someone is looking for a more comprehensive coverage for Postgres, please check out https://github.com/pgschema/pgschema.I built this last summer and thought it was fairly complete. And it turns out I was naive. 6 months later, I have resolved ~100 issues reported by the users.
  • ralferoo
    Sadly, it doesn't handle dropping columns well in sqlite. Actually, it was news to me that DROP COLUMN has been added into sqlite somewhat recently, but certainly the version you'll get on most devices doesn't include it.But anyway, from the example for sqlite, I added "x integer not null," to the original table, and was greeted with "-- Skipped: ALTER TABLE books DROP COLUMN x". Then ticked the "Enable DROP" and got the same, except with the line uncommented.Such a shame, this is one thing that would make a lot of difference. FWIW, the standard way of doing this is creating a temporary table with the new data, dropping the original table, and recreating the new table, copying the data across and deleting the temporary. It's kind of a shame that it doesn't automate that, and this is one of those things that's incredibly easy to mess up if you're not careful, especially if there are constraints involved.If it just does the easy stuff, you might as well just do it by hand.
  • wener
    I use https://github.com/ariga/atlas for this, migration based and schema base both has there good and bad side, I prefer both even in one project, schema based can make dev faster, eaiser, migration based make feel reliable.
  • nopurpose
    Is there a good tool for background migrations?For example add temporarily nullable column to a large table, deploy new code which starts writing to the new column, in background populate that column for existing rows in batches and finally alter column to be mandatory non-nullable.Another example of non-trivial schema management case is to make schema change after new version rollout completes: simple migration at the start of the container can't do that.It must be a solved problem, but I didn't see a good tool for it which would allow expressing these imperative changes in a declarative way which can be comitted and reviewed and tested along the app code. It is always bunch of adhoc ugly scripts on a side and some hand waving deployment instructions.
  • morshu9001
    Pleasantly surprised this post was about a neat little tool and not another migration manager. This always seemed like a weak spot in regular SQL. Wish it were declarative like Spanner DDL.When using Postgres, I just try to keep my schema script idempotent and also work with any version of the DB. Like I start with a CREATE TABLE IF NOT EXISTS, then if I add a new col, it goes into there and also a separate ALTER. But at some point it gets cluttered and I delete the ALTERs once things are stable. Maybe something could hit the fan, I have to restore an old backup from before the last purge, and this tool helps me make it compatible quickly.
  • rswail
    How does this compare to Entity Framework (for dotnet) migrations or sqitch/liquibase.I get the declarative nature of this, but migration of schemas is not purely declarative, particular on large production databases. An ideal schema manager would understand the costs of particular migrations (perhaps by using the table stats and EXPLAIN) and apply that back to the migration strategies so that downtime is minimized/eliminated.Adding or remove columns or indexes can trigger major database table scans and other problems, especially when partitioning conditions change.
  • panzi
    This is very cool!Also means I can stop with my hobby project that was supposed to do the same. Wasn't far along and haven't worked on it in months anyway.So I'll spend my time on another hobby project then that also solves something that is already solved 100 times over, but I don't like the other solutions (simple log monitoring including systemd and sending error emails if something is found).
  • magicalhippo
    We've rolled our own variant of this, which uses an XML file as input. Just easier to parse than SQL schema definitions. The tool compares the schema defined by the XML with the DB, and applies changes as needed.We used Sybase SQLAnywhere, and a complication there was that if you had materialized views against a table, you had to drop and recreate that view when adding or removing columns in the table. And when you recreate it, you of course have to remember to recreate the indexes on that materialized view.Tracking this in case you have multiple materialized views touching multiple tables became a bit tricky, and you don't want to do the "dumb" thing to just always drop and recreate, or per-column, since some of them might take an hour or so to recreate and reindex.The tool has some built-in safeties like never dropping columns if it's missing (have to add explicit element for that in the XML), and only performs safe column definition changes, ie integer to varchar(50) is safe, integer to varchar(3) is not, etc.It really made database migrations very painless for us, great since we've have hundreds of on-premise installations. Just modify the XML, and let the tool do its job.And since its our tool, we can add functionality when we need to.
  • drdaeman
    Looks like this is only useful for empty databases. Which severely limits possible use cases.Schema management is only a small part of the problem, and I don’t think this tool handles data migrations. E.g. if I reshape a JSONB column into something more structured, I don’t think it would be able to handle that. Or if I drop a column the backwards migration it generates ADD COLUMN … NOT NULL, which is obviously unusable if the table has any data in it already.
  • waynenilsen
    This post from 2022 is the one I keep going back tohttps://david.rothlis.net/declarative-schema-migration-for-s...
  • anymouse123456
    I was looking for a dead simple migration tool some years ago and didn’t want a random runtime (and version) dependency to maintain my database.Found shmig and it’s been really fantastic.https://github.com/mbucc/shmig
  • dewey
    I'm always in the market for new sql tooling, but I'm wondering what's the use case there?Isn't it much quicker to write a one line migration vs copying the DDL, then adapting it to the desired state and then getting getting the migrations from that tool? Or am I misunderstanding something?
  • uwemaurer
    This is great! It would be a cool feature to integrate with SQG. there you currently need to provide the sequence of migration steps to get the full schema.https://github.com/sqg-dev/sqg/
  • froh42
    It seems to try to parse the DDL itself, right? I tried only with a few of the PostgreSQL things we use in our schema and and failed parsing theme.g. CREATE TABLE books2 (LIKE book INCLUDING ALL);So I assume it is not Progresql DDL it uses but "something close".
  • systems
    is there anything (open source) similar to microsoft database project but that would work for postgresqli like the following about it 1. database schema is regular code 2. make schema change declaratively 3. packaging (.daspac) and deployement scriptmost open source tools , seem to be after the fact tools, that do diffs ms db project, handle the code from the start in a declarative, source code managed way
  • chmaynard
    Minor quibble: sqlite3 is not a database, it's the CLI for SQLite 3.x
  • gavinray
  • davidkwast
    Wow. I saved the link for emergencies. And I sent it to all my team. It is like a diff tool but to advance the schema.
  • edoceo
    Anyone with real-world usage of this one vs atlas. I've used atlas but it seems to be moving away from FOSS (paywalled-fearures). Its also struggled with some migrations that were a bit more than not trivial (like trying to play changes in the wrong order)
  • stemchar
    I renamed a column and it added a new one.
  • nodesocket
    Looks pretty cool. Lately I've been using ChatGPT to generate SQLite schema migrations and it works shockingly well. I give it the original schema and new schema and it generates the statements including caveats and gotchas to watch out for.
  • Pxtl
    MS' Sql Server Data Tools is such an abominable garbage fire that I have no interest in these kind of tools. Besides being a buggy mess, it's very often insufficient - you end up having to maintain migrations anyways because often you have to inject data into new tables or columns, or rename columns, etc.
  • yearolinuxdsktp
    How is this better than Liquibase? Isn’t there a risk of missing schema evolution steps when you only diff current vs target? (Because current can be v1 and target v3 and you might have lost column migration logic from v2)
  • canadiantim
    Looks great! Could this work with duckdb?