{"id":15003008,"url":"https://github.com/minhhungit/databasemigrateext","last_synced_at":"2025-10-30T09:31:21.508Z","repository":{"id":98218774,"uuid":"104377777","full_name":"minhhungit/DatabaseMigrateExt","owner":"minhhungit","description":"A disciplined way to manage FluentMigration project and track change of stored procedures, sql function...","archived":false,"fork":false,"pushed_at":"2024-04-14T06:29:22.000Z","size":866,"stargazers_count":9,"open_issues_count":2,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-12T07:21:24.814Z","etag":null,"topics":["database-migrate-ext","db-updater","extension","fluentmigrator","mssql-database","sql-version","versioning"],"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/minhhungit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":"FUNDING.yml","license":"LICENSE","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},"funding":{"github":["minhhungit"],"ko_fi":"minhhungit","custom":["https://www.paypal.me/minhhungit"]}},"created_at":"2017-09-21T17:24:06.000Z","updated_at":"2023-05-18T00:30:51.000Z","dependencies_parsed_at":"2024-04-14T07:40:45.898Z","dependency_job_id":null,"html_url":"https://github.com/minhhungit/DatabaseMigrateExt","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhhungit%2FDatabaseMigrateExt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhhungit%2FDatabaseMigrateExt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhhungit%2FDatabaseMigrateExt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/minhhungit%2FDatabaseMigrateExt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/minhhungit","download_url":"https://codeload.github.com/minhhungit/DatabaseMigrateExt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219856480,"owners_count":16556082,"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":["database-migrate-ext","db-updater","extension","fluentmigrator","mssql-database","sql-version","versioning"],"created_at":"2024-09-24T18:54:54.998Z","updated_at":"2025-10-30T09:31:16.113Z","avatar_url":"https://github.com/minhhungit.png","language":"C#","funding_links":["https://github.com/sponsors/minhhungit","https://ko-fi.com/minhhungit","https://www.paypal.me/minhhungit"],"categories":[],"sub_categories":[],"readme":"# \u003cimg rel=\"https://raw.githubusercontent.com/minhhungit/DatabaseMigrateExt/master/develop/Icon/logo.png\" src=\"https://raw.githubusercontent.com/minhhungit/DatabaseMigrateExt/develop/wiki/Icon/logo.png\" width=\"32\" /\u003e DatabaseMigrateExt \u003ca href=\"https://www.nuget.org/packages/DatabaseMigrateExt/\"\u003e\u003cimg src=\"https://img.shields.io/nuget/v/DatabaseMigrateExt.svg?style=flat\" /\u003e\u003c/a\u003e [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d1b3c86714594b6894bb9382c3f85f33)](https://www.codacy.com/app/it.minhhung/DatabaseMigrateExt?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=minhhungit/DatabaseMigrateExt\u0026amp;utm_campaign=Badge_Grade) [![CodeFactor](https://www.codefactor.io/repository/github/minhhungit/databasemigrateext/badge)](https://www.codefactor.io/repository/github/minhhungit/databasemigrateext)\n\nA disciplined way to manage FluentMigration project and track change of stored procedures, sql function...\n\n- [https://minhhungit.github.io/DatabaseMigrateExt](https://minhhungit.github.io/DatabaseMigrateExt)\n\n### Installation\n\u003eInstall-Package DatabaseMigrateExt\n\n### Overview\nWhen we use `Fluent Migrator` or even `EF Migration`, it will be very hard to check history of a sql function/stored procedure, \nDatabaseMigrateExt can help you resolve the problem using ChangeScript/RefScript pattern. \n\nThat means sql function/ stored procedure will be keeped separately in each file (ref-script) \nand every times we want to change we will create a command (change-script) and point to ref-script, for example:\n- We have a ref-script stored proc `dbo.GetProducts`\n- Migration 01 - update `dbo.GetProducts` and commit\n- Migration 02 - update `dbo.GetProducts` and commit again\n- ...\nBy using source control like Git we know history of stored `dbo.GetProducts`\n\nNext, using RefScript/ChangeScript pattern means your stored `dbo.GetProducts` is only one file, so what happen if someday we want to re-run all migrations for a new empty database. \nNormally this will cause a lot errors because file `dbo.GetProducts` is latest state, every times migrator runs it will apply the latest state of the stored procedure, \nin above sample, `Migration 01` and `Migration 02` will call same file `dbo.GetProducts`.\nThere is a high possibility that migratior can not execute your stored procedure because some tables have not created yet.\n\nTo hanlde it, we will need to classify type of change-scripts by using `ExtMigration Attributes`, all migrations relate to schema like Create Database, Alter Column, Created Index, Function... should be run \nbefore Stored Procedure alter migration. Then when you re-run, you will have newest tables, newest schema and Stored Procedure will work.\n\nSo that is what DatabaseMigrateExt does.\n\n### Sample Project\n\nSee [Sample Project](https://github.com/minhhungit/DatabaseMigrateExt/tree/master/Samples) at [https://github.com/minhhungit/DatabaseMigrateExt/tree/master/Samples](https://github.com/minhhungit/DatabaseMigrateExt/tree/master/Samples)\n\n\n### Config\n\n```xml\n\u003cadd key=\"mgr:DatabaseKeys\"     value=\"MovieStore\"/\u003e\n\u003cadd key=\"mgr:RootNamespace\"    value=\"DatabaseMigrateRunner.Migrations\"/\u003e\n\n\u003cadd key=\"mgr:MovieStore_ConnString\"    value=\"Your_ConnectionString_For_MovieStore_At_Here\"/\u003e\n```\n\n*Note*: \n\u003e mgr:MovieStore_ConnString = 'mgr:' + [DatabaseKey] + '_ConnString'\n\nAnytime you want to add new database, just need to add new database name into `mgr:DatabaseKeys` and add new connection key for it.\nMake sure that name of DatabaseKey setting must match with ConnString setting.\n\nFor example:\n```xml\n\u003cadd key=\"mgr:DatabaseKeys\"\t\tvalue=\"MovieStore, InventoryDb, MyNewDatabase\"/\u003e\n\u003cadd key=\"mgr:MovieStore_ConnString\"\tvalue=\"ConnectionString_For_MovieStore\"/\u003e\n\u003cadd key=\"mgr:InventoryDb_ConnString\"   value=\"ConnectionString_For_InventoryDb\"/\u003e\n\u003cadd key=\"mgr:MyNewDatabase_ConnString\"\tvalue=\"ConnectionString_For_MyNewDatabase\"/\u003e\n```\nOf course, you also need a child folder for that database to store migration scripts in `Migrations` folder, like `InvenetoryDb` and `MovieStore` folders (match name with DatabaseKey)\n\n\n### Migration Scripts\n***ExtMigration Attributes:***\n\nThere are 2 attributes:\n- Use `[ExtMgrDataStructureAndFunctions]` for marking the migration as a `STRUCTURE`, a`DATA` or a `FUNCTION` type.\n- Use `[ExtMgrStoredProcedures]` for marking the migration as a`STORED PROCEDURE`.\n\n\u003e Note: System will just find migration scripts which used **ExtMigration Attributes** to apply, everything else will be skipped.\n\nFor example:\n\n```csharp\n[ExtMgrDataStructureAndFunctions(2017, 9, 22, 02, 08, 01)]\npublic class InventoryDb_20170922_020801_inital_tables : ExtDataStructureFunctionMigration\n{\n    public override void Up()\n    {\n        // do someting\n    }\n\n    public override void Down()\n    {\n        throw new NotImplementedException();\n    }        \n}\n```\n\n***Migration structure:***\nYou can put migration classes in everywhere in your project as long as it is placed under availabel namespace.\n\u003e For example: **DatabaseMigrateRunner.Migrations.MovieStore**\n\nRemember that your ref-scripts must be placed fixed in folder @RefScript inside DatabaseKey folder.\nYou can change children folders's name like DataAndStructure/Function/Stored like anything you want with these settings:\n- mgr:SqlDataStructureRefScriptNamespace\n- mgr:SqlFunctionRefScriptNamespace\n- mgr:SqlStoredRefScriptNamespace\n- mgr:SqlGeneralScriptRefScriptNamespace\n\n***Order of migrations:***\nDatabaseMigrateExt will executes migration scripts with bellow order:\n\n- Data, Structure or Function (version number start with 1000..., ex: 100020171021194001)\n- Stored Procedure (version number start with 3000..., ex: 300020190908032101)\n\n| Version            | AppliedOn                | Description                                   |\n|:------------------ |:-------------------------|:----------------------------------------------|\n| 100020171021194001 | 2020-03-24 16:42:18.000\t| MovieStore_20171021_194001_inital_tables      |\n| 100020171022154501 | 2020-03-24 16:42:18.000\t| MovieStore_20171022_154501_inital_function    |\n| 300020170807140103 | 2020-03-24 16:42:18.000\t| MovieStore_20170807_140103_create_stored      |\n| 300020190908032101 | 2020-03-24 16:42:18.000\t| MovieStore_20190908_032101_exec_script        |\n\n***Ref-Script And Change-Script***\n\n\u003cimg src=\"https://raw.githubusercontent.com/minhhungit/DatabaseMigrateExt/master/wiki/Images/ref-and-change-script.png\" /\u003e\n\n### Note \u0026 Tips:\n- Your sql scripts (can be strucuture/stored/funtion...) must be marked as 'Embedded Resource' - you normally just do this one time, after that just need to copy old file and rename - see bellow image :point_down:)\n- DatabaseMigrateExt will find and show all invaild migration scripts when application starts, you should check them\n- DatabaseMigrateExt will not execute invalid scripts\n\n\u003cimg src=\"https://raw.githubusercontent.com/minhhungit/DatabaseMigrateExt/master/wiki/Images/embedded_resource.png\" /\u003e\n\n## Credit\nThe idea of change script/ref script is from [Nghia Nguyen](https://github.com/nghianghesi) aka my boss \n\n### Demo\n\u003cimg src=\"https://raw.githubusercontent.com/minhhungit/DatabaseMigrateExt/master/wiki/Images/demo-result.png\" /\u003e\n\n\n***Sample script:*** \n\n```csharp\nusing DatabaseMigrateExt;\n\nnamespace DatabaseMigrateRunner.Migrations.MovieStore\n{\n    [ExtMgrDataStructureAndFunctions(2017, 9, 22, 02, 08, 01)]\n    public class SqlStructure_20170921_194001_inital_tables : ExtDataStructureFunctionMigration\n    {\n        public override void Up()\n        {\n            // do something here\n        }\n        ....\n    }\n}\n```\nYou also can define author on attribute, like this:\n```csharp\n[ExtMgrDataStructureAndFunctions(\"Hung Vo\", 2017, 9, 22, 02, 08, 01)]\n```\n\n### Run\n```csharp\nusing DatabaseMigrateExt;\n\nstatic void Main(string[] args)\n{\n    // Run migration with default settings\n    ExtMigrationRunner\n        .Initialize()\n        .Process();\n\n    Console.WriteLine(\"Completed!\");\n    Console.ReadKey();\n}\n```\n\n## Thanks\n\u003ca href=\"https://www.jetbrains.com/\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/minhhungit/DatabaseMigrateExt/master/wiki/Images/jetbrains-128x128.png\" /\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminhhungit%2Fdatabasemigrateext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fminhhungit%2Fdatabasemigrateext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fminhhungit%2Fdatabasemigrateext/lists"}