Open metaskills opened 8 years ago
cc @TigerMint as my point of contact on this.
Some notes on playing with the latest docker image which has /opt/mssql/bin/sqlpackage
installed. The below commands will eventually use sqlcmd
vs sqsh
.
We need an empt database to Script against so we drop the test DB and use that. In reality we would use the database task here too.
$ sqsh -U sa -P $SA_PASSWORD -S localhost -C "DROP DATABASE [myapp_test];"
$ sqsh -U sa -P $SA_PASSWORD -S localhost -C "CREATE DATABASE [myapp_test];"
Now we run the sqlpackage commands. Unfortunately this requires being able to run from the host machine.
$ sqlpackage /a:Extract /q:True \
/ssn:tcp:127.0.0.1 /sdn:myapp /su:rails \
/of:True /tf:/opt/mssql/data/structure.dacpac
$ sqlpackage /a:Script \
/sf:/opt/mssql/data/structure.dacpac \
/tsn:tcp:127.0.0.1 /tdn:myapp_test /tu:rails \
/of:True /op:/opt/mssql/data/structure.sql
From here we would need to search and replace the structure file and replace the test database name with the name of the source extract.
-:setvar DatabaseName "myapp_test"
+:setvar DatabaseName "myapp"
$ sqsh -U sa -P $SA_PASSWORD -S localhost -C "DROP DATABASE [myapp_test];"
$ sqsh -U sa -P $SA_PASSWORD -S localhost -C "CREATE DATABASE [myapp_test];"
$ sqlpackage /a:Extract /q:True \
/ssn:tcp:127.0.0.1 /sdn:myapp /su:rails \
/of:True /tf:/opt/mssql/data/structure.dacpac
$ sqlpackage /a:Publish /q:True \
/sf:/opt/mssql/data/structure.dacpac \
/tsn:tcp:127.0.0.1 /tdn:myapp_test /tu:rails
Use new structure_dump_flags
and structure_load_flags
seen here: https://github.com/rails/rails/blob/5-1-stable/activerecord/lib/active_record/tasks/database_tasks.rb
@metaskills what is the status of this feature? do you need any help with it? current defncopy does dump not in a really good way if we talk about syntax
Today, we have a tool called sqlpackage.exe which is a .NET command line app that’s built over a .NET library called DacFX and runs on Windows. This tool supports SQL Server on-premise, SQL Server hosted in a VM and also Azure SQL Database in exactly the same way. More info:
Our current thinking was to make sqlpackage.exe (and DacFX) work on coreclr and corefx so they could be used in Ruby on Rails in scenarios such as dumping schema and/or dumping schema + data for a SQL Server database. Cross Platform!