{"id":21665926,"url":"https://github.com/ackara/daterpillar","last_synced_at":"2025-04-12T01:00:30.156Z","repository":{"id":48241451,"uuid":"48073473","full_name":"Ackara/Daterpillar","owner":"Ackara","description":"Daterpillar is a micro-orm and DevOps toolset that helps you manage databases and generate scripts.","archived":false,"fork":false,"pushed_at":"2023-02-23T03:09:10.000Z","size":9957,"stargazers_count":5,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-27T09:28:33.671Z","etag":null,"topics":["database","devops","migration","mssql","mysql","nuget","schema","sqlite","xml"],"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/Ackara.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.txt","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":"2015-12-15T22:48:26.000Z","updated_at":"2024-06-20T00:02:46.230Z","dependencies_parsed_at":"2024-06-20T00:02:42.758Z","dependency_job_id":"1961a93a-a426-4ce0-9ae0-b94e95f00e00","html_url":"https://github.com/Ackara/Daterpillar","commit_stats":null,"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ackara%2FDaterpillar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ackara%2FDaterpillar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ackara%2FDaterpillar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ackara%2FDaterpillar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ackara","download_url":"https://codeload.github.com/Ackara/Daterpillar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501873,"owners_count":21114683,"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","devops","migration","mssql","mysql","nuget","schema","sqlite","xml"],"created_at":"2024-11-25T11:18:41.507Z","updated_at":"2025-04-12T01:00:30.118Z","avatar_url":"https://github.com/Ackara.png","language":"C#","readme":"# Daterpillar \n\n[![nuget](https://img.shields.io/nuget/v/Daterpillar.svg?maxAge=2592000?style=flat-square)](https://www.nuget.org/packages/Daterpillar)\n[![powershell](https://img.shields.io/powershellgallery/v/daterpillar.svg?style=flat)](https://www.powershellgallery.com/packages/Daterpillar)\n\n## The Problem\nYour *.NET* project depends on a SQL database to store it's data, therefore you need a way to keep your SQL tables in-sync with your entities/classes.\n\n## The Solution\n**Daterpillar** is a *netstandard* library keep your classes and tables in-sync by generating **sql-migration-scripts** from your project's `.dll` file. \n\n### Usage\n\nLets say you have the following class in your project.\n\n```csharp\n// Notice the `User` class is decorated with the `Table` and `Column` attributes.\n\n[Table()]\npublic class User\n{\n    [Key(), Column(AutoIncrement = true)]\n    public string Id { get; set; }\n\n    [Column(\"full_name\", scale: 32)]\n    [StaticId(\"ec35bf5d-9a40-4e6f-8412-852b81807a09\")]\n    public string Name { get; set; }\n\n    public DateTime DOB { get; set; }\n}\n```\n\nThe *NUGET* package ships with a *MSBuild* target called `GenerateDaterpillarMigrationScript`. It will run after the project has been built, and produce a `.sql` script that should update your database schema, but first you will need to configure it. Open your `.*proj` project-file and add the following elements inside a `\u003cPropertyGroup\u003e` element.\n\n```xml\n\u003c!-- This turn on the feature --\u003e\n\u003cShouldGenerateDaterpillarMigrationScriptAfterBuild\u003etrue\u003c/ShouldGenerateDaterpillarMigrationScriptAfterBuild\u003e\n\n\u003c!-- This is where the script will be saved. --\u003e\n\u003cDaterpillarMigrationsDirectory\u003emigrations\u003c/DaterpillarMigrationsDirectory\u003e\n\n\u003c!-- The script's language. --\u003e\n\u003cDaterpillarSqlLanguages\u003eMySQL\u003c/DaterpillarSqlLanguages\u003e\n\n\u003c!-- This file represents the current state/structure of your live database. (Optional defaulats to 'snapshot.schema.xml') --\u003e\n\u003cDaterpillarSnapshotFilePath\u003esnapshot.schema.xml\u003c/DaterpillarSnapshotFilePath\u003e\n```\n\nOnce configured, whenever the project is built, a `.sql` script will be created. \n\n```sql\n# EXAMPLE: `V1.0.0__create_schema.mysql.sql`\nCREATE TABLE `user`(\n    `Id` VARCHAR(64) NOT NULL PRIMARY KEY AUTO_INCREMENT,\n    `full_name` VARCHAR(32) NOT NULL,\n    `DOB` DATETIME NOT NULL\n);\n```\n\nIt is also possible to generate a new script at runtime.\n\n```csharp\nvar migrator = new Migrator();\nmigrator.GenerateMigrationScript(Language.MySQL, typeof(User).Assembly, snapshotFilePath, migrationDirectory, fileName);\n```\n\nNow that you have a migration-script you will probably want to run it. You can run the script manually or use other tools like [Evolve](https://www.nuget.org/packages/Evolve/), [FlywayDB](https://flywaydb.org/) or [Powershell](https://www.powershellgallery.com/packages/Daterpillar). \n\n#### More about .schema.xml\n\nTo generated the migration-script mentioned earlier, the difference between `snapshot.schema.xml` and `[your-assembly].schema.xml` is used to generate the script. So where did this `[your-assembly].schema.xml` file came from? The *MSBuild* target `ExportDaterpillarSchema`, and it is executed after each successful build. You can extend a schema by merging multiple schemas together. Lets say you want to add seed-data to a table, first you will have to add a `[assembly: Import(\"seed.schema.xml\")]` attribute to your project. \n\n```csharp\n// example: `./Properties/AssemblyInfo.cs`\n...\n[assembly: Acklann.Daterpillar.Import(\"seed.schema.xml\")]\n// or\n// [assembly: Acklann.Daterpillar.Import(\"*.schema.xml\")]\n...\n```\n\nNext add the `seed.schema.xml` to your project, and make sure it is being copied next to the `.dll` (**Copy To Output Directory: Copy if newer**).\n\n```xml\n\u003cschema xmlns=\"https://raw.githubusercontent.com/Ackara/Daterpillar/master/src/Daterpillar/daterpillar.xsd\"\u003e\n    \u003c!-- This script will be appended --\u003e\n    \u003cscript name=\"seed\" language=\"MySQL\"\u003e\n    INSERT INTO User (full_name, DOB) VALUES ('Petra Ral', '2000-11-15');\n    \u003c/script\u003e\n\u003c/schema\u003e\n```\n\nYou can also override or add columns by redefining a table.\n\n```xml\n\u003cschema xmlns=\"https://raw.githubusercontent.com/Ackara/Daterpillar/master/src/Daterpillar/daterpillar.xsd\"\u003e\n    \u003ctable name=\"User\"\u003e\n        \u003c!-- This will rename the existing 'full_name' column --\u003e\n        \u003ccolumn id=\"ec35bf5d-9a40-4e6f-8412-852b81807a09\" name=\"first_name\"\u003e\n            \u003cdataType scale=\"64\"\u003evarchar\u003c/dataType\u003e\n        \u003c/column\u003e\n\n        \u003c!-- This will add a new column --\u003e\n        \u003ccolumn name=\"last_name\"\u003e\n            \u003cdataType scale=\"64\"\u003evarchar\u003c/dataType\u003e\n        \u003c/column\u003e\n    \u003c/table\u003e\n\u003c/schema\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fackara%2Fdaterpillar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fackara%2Fdaterpillar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fackara%2Fdaterpillar/lists"}