https://github.com/piotrekh/dbup-add-migration
Package manager console command "Add-Migration" that creates an sql file with date and time (yyyyMMddHHmmss) in the file name (e.g. 20170730185349_Migration.sql)
https://github.com/piotrekh/dbup-add-migration
database database-migrations dbup migrations sql-files
Last synced: 5 months ago
JSON representation
Package manager console command "Add-Migration" that creates an sql file with date and time (yyyyMMddHHmmss) in the file name (e.g. 20170730185349_Migration.sql)
- Host: GitHub
- URL: https://github.com/piotrekh/dbup-add-migration
- Owner: piotrekh
- License: mit
- Created: 2017-07-30T17:32:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-02-24T16:12:34.000Z (over 6 years ago)
- Last Synced: 2025-08-19T17:52:18.538Z (9 months ago)
- Topics: database, database-migrations, dbup, migrations, sql-files
- Language: PowerShell
- Size: 10.7 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/dbup-add-migration/)
[](https://www.nuget.org/packages/dbup-add-migration/)
# Add-Migration command for DbUp
**Add-Migration** Package Manager Console command intended for use with [DbUp](http://dbup.github.io/) (but not depending on it)
## Requirements
- Powershell 5
## About
This package adds a new command **"Add-Migration"** (and **"Add-DbUpMigration"** alias) to the Package Manager Console. Running the command results in an sql file with date and time (in format _yyyyMMddHHmmss_) in the file name added to the project (e.g. `20170730185349_MyFirstMigration.sql`).
Create a file using default behaviour (the command will decide where to put it, build action will not be set):
Add-Migration "MyFirstMigration"
Create a file in specific folder:
Add-Migration "MyFirstMigration" -Folder "Migrations"
Set build action when creating a file (use tab for -BuildAction value hints):
Add-Migration "MyFirstMigration" -BuildAction EmbeddedResource
**If you experience issues with `Add-Migration` command being overwritten by the EF migrations' command (which has the same name), please use the alias `Add-DbUpMigration` or prefix the command with package name: `dbup-add-migration\Add-Migration`**
---
The sql files are generated in either of these locations in your project:
- _Specified folder_ - when `-Folder` parameter is added, the script will be generated in the given directory. If the directory does not exist, it will be created.
- _"Migrations" folder_ - when `-Folder` parameter is omitted, but a folder named "Migrations" already exists in the project.
- _"Scripts" folder_ - when `-Folder` parameter is omitted, but a folder named "Scripts" already exists in the project.
- _First folder with .sql files_ - when `-Folder` parameter is omitted and neither "Migrations" nor "Scripts" folder exists, the command will add the new migration in the first folder in the project that contains .sql files. If no such folder is found, then "Migrations" folder will be created and used by default.
---
When `-BuildAction` parameter is set to _Content_, the command will also set **Copy to output directory** to _Copy always_
---
## Optional settings file
If you don't want to specify the `-BuildAction` or `-Folder` parameter everytime you add a new migration, you can add an optional settings file to your project by executing the following command:
Add-MigrationSettings
This command will add `dbup-add-migration.json` file to your project (if it doesn't exist yet) with default configuration for the Add-Migration command:
```
{
"folder": "Migrations",
"buildAction": "EmbeddedResource"
}
```
---
The "buildAction" field should contain one of the following values:
- None
- Compile
- Content
- EmbeddedResource
---
However, if you have the settings file in your project and specify the `-BuildAction` or `-Folder` parameters anyway when generating a new migration, they will take precedence over the values in `dbup-add-migration.json`
## How to install
You can install this package from [NuGet](https://www.nuget.org/packages/dbup-add-migration/)
Install-Package dbup-add-migration