Skip to content

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)

License

Notifications You must be signed in to change notification settings

piotrekh/dbup-add-migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NuGet NuGet

Add-Migration command for DbUp

Add-Migration Package Manager Console command intended for use with DbUp (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

Install-Package dbup-add-migration

About

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)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published