Thanks for the reply!
We actually do something similar with our migrations. We use migrate which is run as part of our CI pipeline. My suggestion above doesn’t stop the need for migrations to be run.
What I am suggesting is the use of a single schema file which describes the database schema declaratively, without having to use
IF NOT EXISTS statements whenever a change is made. You just update the schema you already have and allow cockroachdb to work out the delta and ADD/DROP columns etc accordingly.
This allows developers to use their
schema.sql as a source of truth, without having to scan through multiple ALTER lines to get an understanding of the model.
It also allows for better tooling to be built around schema files. For example, parsers can be built to code generate models from a schema, without having to understand ALTER statements. You could also generate schema files from code first models, perhaps even run as part of application code, which opens up some interesting possibilities.