microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
337 stars 59 forks source link

Add support for more file types (beyond .bak) in the --using flag (sqlcmd create) #210

Open stuartpa opened 1 year ago

stuartpa commented 1 year ago

The initial PR for the --using flag (in sqlcmd create mssql) enables the scenario:

sqlcmd create mssql --using https://aka.ms//AdventureWorksLT.bak

i.e. create a new local T/SQL endpoint with the AdventureWorks database downloaded and restored from a URL

--using should support all normal source type that contain databases, e.g. .bacpac files, and .mdf/.ldf (in archive files, like .zip/.7z etc.).

--using should just do the right thing depending on what it finds, e.g. do a restore of a .bak file / do an attach of a .mdf/.ldf file etc.

--using should also support more protcols than just http(s)://, it should definitely support file:\, including c:\ etc.

(the idea here is the end user shouldn't need to know the mechanism required to get the database attached to the engine, they just provide the URL to the file, and sqlcmd does the rest).

stuartpa commented 1 year ago

Also add support for SAS tokens when using https URL to Azure Storage. And support managed identity auth as well.

stuartpa commented 1 year ago

This is how a user can hack up .bacpac support today, make this a seamless part of the --using flag:

sqlcmd create mssql --user-database db1|sleep 5; echo sleeping; sleep 3|sqlpackage /a:import /SourceFile:db1.bacpac /tu:"username" /tp:"REDACTED" /tsn:"localhost,1433" /tdn:"db1"
giammin commented 1 year ago

--using should also support more protcols than just http(s)://, it should definitely support file:\, including c:\ etc.

this would be awesome. you could create a dev database from a backup in seconds

I expected it to work already with a local path. Don't understand the limitation to only use url

stuartpa commented 1 year ago

--using should also support more protcols than just http(s)://, it should definitely support file:, including c:\ etc.

this would be awesome. you could create a dev database from a backup in seconds

I expected it to work already with a local path. Don't understand the limitation to only use url

@giammin, check out #319, is there missing from this PR? We implemented this initial --using support as an MVP in the spirit of Ries' "Lean Startup". This functionality was asked for very clearly in early user testing of sqlcmd create. The feedback has been very positive, and we are looking to round out the MVP now.

giammin commented 1 year ago

nothing missing, awesome work!