Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace TinyTDS/FreeTDS defncopy bin with Cross Platform SqlPackage.exe #437

Open
metaskills opened this issue Jan 16, 2016 · 6 comments
Open
Labels

Comments

@metaskills
Copy link
Member

metaskills commented Jan 16, 2016

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!

@metaskills
Copy link
Member Author

cc @tigermint as my point of contact on this.

@metaskills
Copy link
Member Author

Linking microsoft/mssql-docker#8

@metaskills
Copy link
Member Author

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.

Structure Dump

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"

Structure Clone/Load

$ 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

@metaskills
Copy link
Member Author

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

@vkalach
Copy link

vkalach commented Aug 30, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants