{"id":19397906,"url":"https://github.com/max-ieremenko/sqldatabase","last_synced_at":"2025-05-06T21:29:00.077Z","repository":{"id":45276009,"uuid":"125847528","full_name":"max-ieremenko/SqlDatabase","owner":"max-ieremenko","description":"Command-line tool and PowerShell module for MSSQL Server, PostgreSQL and MySQL.","archived":false,"fork":false,"pushed_at":"2024-11-09T09:40:06.000Z","size":9398,"stargazers_count":13,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T07:18:45.659Z","etag":null,"topics":["c-sharp","command-line-tool","database-migrations","export-data","migration-tool","miration-step","mysql","mysql-database","postgresql","postgresql-tool","powershell","sql-database","sql-script","sql-server","sqlcmd","sqldatabase","sqlserver"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/max-ieremenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-19T11:30:25.000Z","updated_at":"2024-11-25T16:51:32.000Z","dependencies_parsed_at":"2023-11-28T03:41:28.756Z","dependency_job_id":"2a8bca12-f3d6-4b97-8b41-fdbcb3ccf611","html_url":"https://github.com/max-ieremenko/SqlDatabase","commit_stats":{"total_commits":374,"total_committers":5,"mean_commits":74.8,"dds":0.06951871657754005,"last_synced_commit":"64ada59ca7d6540c5c9d9c19a8439c2b05471dcc"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-ieremenko%2FSqlDatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-ieremenko%2FSqlDatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-ieremenko%2FSqlDatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-ieremenko%2FSqlDatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/max-ieremenko","download_url":"https://codeload.github.com/max-ieremenko/SqlDatabase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252771540,"owners_count":21801731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","command-line-tool","database-migrations","export-data","migration-tool","miration-step","mysql","mysql-database","postgresql","postgresql-tool","powershell","sql-database","sql-script","sql-server","sqlcmd","sqldatabase","sqlserver"],"created_at":"2024-11-10T11:03:29.786Z","updated_at":"2025-05-06T21:29:00.055Z","avatar_url":"https://github.com/max-ieremenko.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"SqlDatabase\n===========\n\n[![NuGet](https://img.shields.io/nuget/v/SqlDatabase.svg?style=flat-square\u0026label=nuget%20net%204.7.2)](https://www.nuget.org/packages/SqlDatabase/)\n[![NuGet](https://img.shields.io/nuget/v/SqlDatabase.GlobalTool.svg?style=flat-square\u0026label=nuget%20dotnet%20tool)](https://www.nuget.org/packages/SqlDatabase.GlobalTool/)\n[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/SqlDatabase.svg?style=flat-square)](https://www.powershellgallery.com/packages/SqlDatabase)\n[![GitHub release](https://img.shields.io/github/release/max-ieremenko/SqlDatabase.svg?style=flat-square\u0026label=manual%20download)](https://github.com/max-ieremenko/SqlDatabase/releases)\n\nCommand-line tool and PowerShell module for MSSQL Server, PostgreSQL and MySQL allows to execute scripts, database migrations and export data.\n\nTable of Contents\n-----------------\n\n\u003c!-- toc --\u003e\n  \n- [SqlDatabase](#sqldatabase)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n    - [PowerShell, from gallery](#powershell-from-gallery)\n    - [PowerShell, manual release download](#powershell-manual-release-download)\n    - [Dotnet sdk tool](#dotnet-sdk-tool)\n  - [Target database type selection ](#target-database-type-selection-)\n  - [Execute script(s) ](#execute-scripts-)\n  - [Export data from a database to sql script (file) ](#export-data-from-a-database-to-sql-script-file-)\n  - [Create a database ](#create-a-database-)\n  - [Migrate an existing database ](#migrate-an-existing-database-)\n  - [Scripts](#scripts)\n  - [Variables](#variables)\n      - [Example](#example)\n      - [Example how to hide variable value from a log output](#example-how-to-hide-variable-value-from-a-log-output)\n    - [Predefined variables](#predefined-variables)\n  - [\\*.zip files ](#zip-files-)\n  - [VS Package manager console ](#vs-package-manager-console-)\n  - [Examples](#examples)\n  - [License](#license)\n\n\u003c!-- tocstop --\u003e\n\nInstallation\n------------\n\nPowerShell module is compatible with Powershell Core 7.2+ and PowerShell Desktop 5.1.\n\n.net tool is compatible with .net sdk 9.0, 8.0 and 6.0.\n\nCommand-line tool is compatible with .net runtime 9.0, 8.0, 6.0 and .net framework 4.7.2+.\n\n### PowerShell, from gallery\n\n[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/SqlDatabase.svg?style=flat-square)](https://www.powershellgallery.com/packages/SqlDatabase)\n\n```powershell\nPS\u003e Install-Module -Name SqlDatabase\n```\n\n### PowerShell, manual [release](https://github.com/max-ieremenko/SqlDatabase/releases) download\n\n[![GitHub release](https://img.shields.io/github/release/max-ieremenko/SqlDatabase.svg?style=flat-square\u0026label=manual%20download)](https://github.com/max-ieremenko/SqlDatabase/releases)\n\n```powershell\nPS\u003e Import-Module .\\SqlDatabase.psm1\n```\n\n### Dotnet sdk tool\n\n[![NuGet](https://img.shields.io/nuget/v/SqlDatabase.GlobalTool.svg?style=flat-square\u0026label=nuget%20dotnet%20tool)](https://www.nuget.org/packages/SqlDatabase.GlobalTool/)\n\n```bash\n$ dotnet tool install --global SqlDatabase.GlobalTool\n```\n\n[Back to ToC](#table-of-contents)\n\nTarget database type selection \u003ca name=\"database-selection\"\u003e\u003c/a\u003e\n--------------\n\nThe target database/server type is recognized automatically from provided connection string:\n\nhere is target MSSQL Server (keywords `Data Source` and `Initial Catalog`):\n\n```bash\n$ SqlDatabase [command] \"-database=Data Source=server;Initial Catalog=database;Integrated Security=True\"\n\nPS\u003e *-SqlDatabase -database \"Data Source=server;Initial Catalog=database;Integrated Security=True\"\n```\n\nhere is target PostgreSQL (keywords `Host` and `Database`):\n\n```bash\n$ SqlDatabase [command] \"-database=Host=server;Username=postgres;Password=qwerty;Database=database\"\n\nPS\u003e *-SqlDatabase -database \"Host=server;Username=postgres;Password=qwerty;Database=database\"\n```\n\nhere is target MySQL (keywords `Server` and `Database`):\n\n```bash\n$ SqlDatabase [command] \"-database=Server=localhost;Database=database;User ID=root;Password=qwerty;\"\n\nPS\u003e *-SqlDatabase -database \"Server=localhost;Database=database;User ID=root;Password=qwerty;\"\n```\n\n[Back to ToC](#table-of-contents)\n\nExecute script(s) \u003ca name=\"execute-script\"\u003e\u003c/a\u003e\n--------------\n\nexecute script from file \"c:\\Scripts\\script.sql\" on *[MyDatabase]* on server *[MyServer]* with \"Variable1=value1\" and \"Variable2=value2\"\n\n```bash\n$ SqlDatabase execute ^\n      \"-database=Data Source=server;Initial Catalog=database;Integrated Security=True\" ^\n      -from=c:\\Scripts\\script.sql ^\n      -varVariable1=value1 ^\n      -varVariable2=value2\n\nPS\u003e Execute-SqlDatabase `\n      -database \"Data Source=server;Initial Catalog=database;Integrated Security=True\" `\n      -from c:\\Scripts\\script.sql `\n      -var Variable1=value1,Variable2=value2 `\n      -InformationAction Continue\n```\n\n See more details [here](Examples/ExecuteScriptsFolder).\n\n[Back to ToC](#table-of-contents)\n\nExport data from a database to sql script (file) \u003ca name=\"export-data\"\u003e\u003c/a\u003e\n--------------\n\nexport data from sys.databases view into \"c:\\databases.sql\" from \"MyDatabase\" on \"server\"\n\n```bash\n$ SqlDatabase export ^\n      \"-database=Data Source=server;Initial Catalog=database;Integrated Security=True\" ^\n      \"-fromSql=SELECT * FROM sys.databases\" ^\n      -toFile=c:\\databases.sql\n\nPS\u003e Export-SqlDatabase `\n      -database \"Data Source=server;Initial Catalog=database;Integrated Security=True\" `\n      -fromSql \"SELECT * FROM sys.databases\" `\n      -toFile c:\\databases.sql `\n      -InformationAction Continue\n```\n\n See more details [here](Examples/ExportData).\n\n[Back to ToC](#table-of-contents)\n\nCreate a database \u003ca name=\"create-database\"\u003e\u003c/a\u003e\n---------------\n\ncreate new database *[MyDatabase]* on server *[MyServer]* from scripts in *[Examples\\CreateDatabaseFolder]* with \"Variable1=value1\" and \"Variable2=value2\"\n\n```bash\n$ SqlDatabase create ^\n      \"-database=Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True\" ^\n      -from=Examples\\CreateDatabaseFolder ^\n      -varVariable1=value1 ^\n      -varVariable2=value2\n\nPS\u003e Create-SqlDatabase `\n      -database \"Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True\" `\n      -from Examples\\CreateDatabaseFolder `\n      -var Variable1=value1,Variable2=value2 `\n      -InformationAction Continue\n```\n\n See more details [here](Examples/CreateDatabaseFolder).\n\n[Back to ToC](#table-of-contents)\n\nMigrate an existing database \u003ca name=\"upgrade-database\"\u003e\u003c/a\u003e\n----------------\n\nupgrade existing database *[MyDatabase]* on server *[MyServer]* from scripts in *Examples\\MigrationStepsFolder* with \"Variable1=value1\" and \"Variable2=value2\"\n\n```bash\n$ SqlDatabase upgrade ^\n      \"-database=Data Source=server;Initial Catalog=MyDatabase;Integrated Security=True\" ^\n      -from=Examples\\MigrationStepsFolder ^\n      -varVariable1=value1 ^\n      -varVariable2=value2\n\nPS\u003e Upgrade-SqlDatabase `\n      -database \"Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True\" `\n      -from Examples\\MigrationStepsFolder `\n      -var Variable1=value1,Variable2=value2 `\n      -InformationAction Continue\n```\n\n See more details [here](Examples/MigrationStepsFolder).\n\n[Back to ToC](#table-of-contents)\n\nScripts\n-------\n\n- *.sql* a text file with sql scripts\n- *.ps1* a text file with PowerShell script, details are [here](Examples/PowerShellScript)\n- *.dll* or *.exe* an .NET assembly with a script implementation, details are [here](Examples/CSharpMirationStep)\n\n[Back to ToC](#table-of-contents)\n\nVariables\n---------\n\nIn a sql text file any entry like *{{VariableName}}* or *$(VariableName)* is interpreted as variable and has to be changed (text replacement) with a value before script execution.\nThe variable name is\n\n- a word from characters a-z, A-Z, 0-9, including the _ (underscore) character\n- case insensitive\n\n#### Example\n\n```sql\n-- script.sql\nPRINT 'drop table {{Schema}}.{{Table}}'\nDROP TABLE [{{Schema}}].[{{Table}}]\n```\n\n```bash\n# execute script.sql\n$ SqlDatabase execute -from=script.sql -varSchema=dbo -varTable=Person\nPS\u003e Execute-SqlDatabase -from script.sql -var Schema=dbo,Table=Person -InformationAction Continue\n\n# log output\nscript.sql ...\n   variable Schema was replaced with dbo\n   variable Table was replaced with Person\n```\n\n```sql\n-- script at runtime\nPRINT 'drop table dbo.Person'\nDROP TABLE [dbo].[Person]\n```\n\n#### Example how to hide variable value from a log output\n\nIf a name of variable starts with _ (underscore) character, for instance *_Password*, the value of variable will not be shown in the log output.\n\n```sql\n-- script.sql\nALTER LOGIN [sa] WITH PASSWORD=N'{{_Password}}'\n```\n\n```bash\n# execute script.sql\n$ SqlDatabase execute -from=script.sql -var_Password=P@ssw0rd\nPS\u003e Execute-SqlDatabase -from script.sql -var _Password=P@ssw0rd -InformationAction Continue\n\n# log output\nscript.sql ...\n   variable _Password was replaced with [value is hidden]\n```\n\n```sql\n-- script at runtime\nALTER LOGIN [sa] WITH PASSWORD=N'{{P@ssw0rd}}'\n```\n\nA non defined variable`s value leads to an error and stops script execution process.\n\nThe variable value is resolved in the following order:\n\n1. check command line\n2. check environment variables (Environment.GetEnvironmentVariable())\n3. check [configuration file](Examples/ConfigurationFile)\n\n### Predefined variables\n\n- *DatabaseName* - the target database name, see connection string (-database=...Initial Catalog=MyDatabase...)\n- *CurrentVersion* - the database/module version before execution of a [migration step](Examples/MigrationStepsFolder)\n- *TargetVersion* - the database/module version after execution of a [migration step](Examples/MigrationStepsFolder)\n- *ModuleName* - the module name of current [migration step](Examples/MigrationStepsFolder), empty string in case of straight forward upgrade\n\n[Back to ToC](#table-of-contents)\n\n*.zip files \u003ca name=\"zip-files\"\u003e\u003c/a\u003e\n------------------------------------\n\nParameters *-from* and *-configuration* in the command line interpret .zip files in the path as folders, for example\n\n- -from=c:\\scripts.zip\\archive\\tables.zip\\demo\n- -from=c:\\scripts.zip\\archive\\tables.zip\\table1.sql\n- -configuration=c:\\scripts.zip\\app.config\n\n[Back to ToC](#table-of-contents)\n\n\nVS Package manager console \u003ca name=\"console\"\u003e\u003c/a\u003e\n------------------------------------------------\n\nFor integrating SqlDatabase into the Visual studio package manager console please check this [example](Examples/PackageManagerConsole).\n\n[Back to ToC](#table-of-contents)\n\nExamples\n--------\n\n- [create ms sql server linux docker image](Examples/SqlServerDockerImage)\n- [execute script(s)](Examples/ExecuteScriptsFolder)\n- [export data](Examples/ExportData)\n- [create a database](Examples/CreateDatabaseFolder)\n- [upgrade an existing database](Examples/MigrationStepsFolder)\n- [how to use SqlDatabase in the VS Package manager console](Examples/PackageManagerConsole)\n- [configuration file](Examples/ConfigurationFile)\n- [assembly script](Examples/CSharpMirationStep)\n\n[Back to ToC](#table-of-contents)\n\nLicense\n-------\n\nThis tool is distributed under the [MIT](LICENSE.md) license.\n\n[Back to ToC](#table-of-contents)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmax-ieremenko%2Fsqldatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmax-ieremenko%2Fsqldatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmax-ieremenko%2Fsqldatabase/lists"}