Open mgravell opened 12 months ago
Sort the table names, and the column names before writing file so diff/merge more likely to work in a senible way. The file should always be 100% same if database is logically the same.
Also think of how a build server could run tool to check that file is the same when database creation script is run then checked in file. But leave details of implementation to the users build management team.
For inspiration, this exists in PHP land: https://github.com/staabm/phpstan-dba
Not sure if you're aware about this, but I think this exists in F# already as a type provider: https://fsprojects.github.io/SQLProvider/
context: https://twitter.com/IanStockport/status/1702313925810024716
imagine a "dotnet tool":
which:
conn-key
dbschema.txt
Where
dbschema.txt
could be something like (is there prior art here? plain text?):(note on order: objects are invariant alphabetical; columns/parameters/etc are positional)
we would then load the
dbschema.txt
and use it to validate commands at build time, without needing constant SQL access. Schema should be implied via "default schema" when omitted.Possible checks:
sp_helptext
-etc source and parse that too?)Rewriting the db schema would be a case of re-running the tool, with the changes visible in source control.
Note: advanced SQL analysis is currently limited to SQL Server; we should probably at least not assume that when connecting (use the provider model), but... whatever works.