SlideShare a Scribd company logo
1 of 40
To Put Your Schema in Git
July 2023
Matthew D. Groves | DevRel Engineer
Using Fluent Migrations
2
My Migration Story
The Bad Old Days
3
Who am I?
• Matthew D. Groves
• Couchbase, DevRel Engineer
• Author (Manning, Apress, Pluralsight)
• Streamer: https://twitch.tv/matthewdgroves
• https://twitter.com/mgroves
• C# Advent creator
To Put Your Schema in Git
August 2023
Matthew D. Groves | DevRel Engineer
Using Fluent Migrations
01/
02/
03/
04/
05/
06/
Intro
Why (Fluent) Migration?
Demo
Select Features
Why NOT use it?
NoSQL
Agenda
07/ Next Steps
6
2 Why (Fluent) Migration?
7
My Migration Story
The Bad Old Days
8
My Migration Story
The Bad Old Days
9
My Migration Story
The Bad Old Days
10
What is Migration?
1. Write a script to make change(s) to a database schema
• E.g. "create a table" or "alter a table"
2. Script generally corresponds to a feature change in the code base
3. Commit the script with the feature change to source control
4. Run all scripts one-by-one and/or compile all scripts into a single script
NOT migration of data from one database to another
11
Why use Migration?
• Version Control 📂⏰
• Automation ⚙⏰
• Documentation 📄📕
• Collaboration ⏰👥
12
Why use FluentMigrator?
• 💡 Fluent, intuitive. Discoverable API
• 🔗C# / .NET
• 🌐 Database independence
• ⏰ Automation
Create.Slide("BulletPoints").With("Emojis")
13
3 Getting Started
Demo
15
4 FluentMigrator
Features
16
using FluentMigrator;
using System;
namespace YourCompany.YourProduct.Database.Maintenance
{
public class TagNames
{
public const string Development = nameof(Development);
}
[Tags(TagNames.Development)]
[Maintenance(MigrationStage.BeforeAll, TransactionBehavior.None)]
public class DevBeforeAll : ForwardOnlyMigration
{
public override void Up()
{
System.Console.WriteLine($"Tag=[{TagNames.Development}] Stage=[{MigrationStage.BeforeAll}]");
}
}
}
Maintenance Migrations
Run Logic Every Time
17
[Tags("DK", "NL", "UK")]
[Tags("Staging", "Production")]
[Migration(1)]
public class DoSomeStuffToEuropeanStagingAndProdDbs : Migration
{
/* ... etc ... */
}
Tags
Filtering Migrations
18
/// <summary>
/// Mark all migrations with this INSTEAD of [Migration].
/// </summary>
public class MyCustomMigrationAttribute : FluentMigrator.MigrationAttribute
{
public MyCustomMigrationAttribute(int branchNumber, int year, int month, int day, int hour, int minute, string author)
: base(CalculateValue(branchNumber, year, month, day, hour, minute))
{
this.Author = author;
}
public string Author { get; private set; }
private static long CalculateValue(int branchNumber, int year, int month, int day, int hour, int minute)
{
return branchNumber * 1000000000000L + year * 100000000L + month * 1000000L + day * 10000L + hour * 100L + minute;
}
}
[MyCustomMigration(author: "Scott Stafford", branchNumber: 12, year: 2012, month: 8, day: 7, hour: 14, minute: 01)]
public class TestLcmpMigration : Migration
{
public override void Down() { /* ... */ }
public override void Up() { /* ... */ }
}
Enforce Version Numbering
One Standard for the Whole Team
19
public class YourConventionSet : IConventionSet
{
public YourConventionSet() : this(new DefaultConventionSet()) { }
public YourConventionSet(IConventionSet innerConventionSet)
{
ForeignKeyConventions = new List<IForeignKeyConvention>()
{
/* This is where you do your stuff */
new YourCustomDefaultForeignKeyNameConvention(),
innerConventionSet.SchemaConvention,
};
ColumnsConventions = innerConventionSet.ColumnsConventions;
ConstraintConventions = innerConventionSet.ConstraintConventions;
IndexConventions = innerConventionSet.IndexConventions;
SequenceConventions = innerConventionSet.SequenceConventions;
AutoNameConventions = innerConventionSet.AutoNameConventions;
SchemaConvention = innerConventionSet.SchemaConvention;
RootPathConvention = innerConventionSet.RootPathConvention;
}
/// ... etc ...
}
Naming Conventions
What if my tables are named with GIANT_SNAKE_CASE?
20
[Migration(201207080104)]
public class RenameTableWithSchema : AutoReversingMigration
{
public override void Up()
{
Rename.Table("TestTable2")
.InSchema("TestSchema")
.To("TestTable'3");
}
}
Auto-Reversing
Such a Down()er
21
dotnet-fm migrate
-m Session
-p sqlserver2012
-c "<connection string here>"
-a "./path/to/YourMigrations.dll"
Transactions
Begin / Commit / Rollback
22
5 Why NOT use it?
23
Top 5 Reasons NOT to use Fluent Migrator
Number 3 will SHOCK you
24
Why NOT use FluentMigrator?
1. 💧 All Abstractions are leaky
5 Reasons
25
Why NOT use FluentMigrator?
1. 💧 All Abstractions are leaky
2. ⏰It's C#. How does your DBA feel about it?
5 Reasons
26
Why NOT use FluentMigrator?
1. 💧 All Abstractions are leaky
2. ⏰ It's C#. How does your DBA feel about it?
3. ⚙ Sprocs / views / triggers
5 Reasons
27
Why NOT use FluentMigrator?
1. 💧 All Abstractions are leaky
2. ⏰ It's C#. How does your DBA feel about it?
3. ⚙ Sprocs / views / triggers
4. ♊Potential duplication of concerns
5 Reasons
28
Why NOT use FluentMigrator?
1. 💧 All Abstractions are leaky
2. ⏰ It's C#. How does your DBA feel about it?
3. ⚙ Sprocs / views / triggers
4. ♊Potential duplication of concerns
5. 🎯 Database-specific features
5 Reasons
29
6 NoSQL
30
Couchbase is a JSON database
NoSQL = No schema, right?
31
Couchbase is a JSON database
NoSQL = No schema, right?
32
Couchbase is a JSON database
SQL Server Couchbase Note
Server Cluster ➕ Scalability / High Availability / Built-in caching
Catalog (Database) Bucket
Schema Scope Often just "dbo" in SQL Server or "_default" in Couchbase
Table Collection ➖ Pre-defined columns/constraints
Row Document ➕ Flexible JSON
tSQL SQL++ (Previously known as N1QL in Couchbase)
Primary Key Document Key ➖ Compound keys
➖ "No" keys
Index Index
33
NoSQL Support for Fluent Migrator?
Instead of
Create.Table(. . .)
what if there was
Create.Collection(. . .)
?
34
Introducing: NoSQLMigrator
35
[Migration(1)]
public class Migration001_CreateInitialScopeAndCollection : Migrate
{
public override void Up()
{
Create.Scope("myScope")
.WithCollection("myCollection1");
}
public override void Down()
{
Delete.Scope("myScope");
}
}
NoSqlMigrator in Action
Look familiar?
36
7 Next Steps
37
Try FluentMigrator
• https://github.com/mgroves/FluentMigratorDemo
• https://fluentmigrator.github.io/
• dotnet add package FluentMigrator
How to get started
38
Try Couchbase Capella
• Free Playground: https://couchbase.live
• Free Trial (no credit card needed!)
• https://www.couchbase.com/products/capella/
• Ask me about Couchbase!
39
Tell Someone!
• Hashtag it: #DaytonDotNet? #GemCityTech?
• #Couchbase
• https://twitter.com/mgroves
• Tell your team!
• Write, make a video, podcast, etc!
• https://csadvent.christmas
Learn something interesting?
THANK YOU

More Related Content

Similar to FluentMigrator - Dayton .NET - July 2023

InteropWG Intro & Vertical Programs (May. 2017)
InteropWG Intro & Vertical Programs (May. 2017)InteropWG Intro & Vertical Programs (May. 2017)
InteropWG Intro & Vertical Programs (May. 2017)Mark Voelker
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkBob German
 
Introduction to Meteor - revised edition
Introduction to Meteor - revised editionIntroduction to Meteor - revised edition
Introduction to Meteor - revised editionStephan Hochhaus
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional testHarry Zheng
 
DevOpsGuys - DevOps Automation - The Good, The Bad and The Ugly
DevOpsGuys - DevOps Automation - The Good, The Bad and The UglyDevOpsGuys - DevOps Automation - The Good, The Bad and The Ugly
DevOpsGuys - DevOps Automation - The Good, The Bad and The UglyDevOpsGroup
 
Automation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit Europe
Automation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit EuropeAutomation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit Europe
Automation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit EuropeAppDynamics
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresFrits Van Der Holst
 
YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»
YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»
YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»GoQA
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationJonathan Katz
 
Continuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsContinuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsMike Brittain
 
Grokking #9: Building a real-time and offline editing service with Couchbase
Grokking #9: Building a real-time and offline editing service with CouchbaseGrokking #9: Building a real-time and offline editing service with Couchbase
Grokking #9: Building a real-time and offline editing service with CouchbaseOliver N
 
Free GitOps Workshop
Free GitOps WorkshopFree GitOps Workshop
Free GitOps WorkshopWeaveworks
 
MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)Peter Presnell
 
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニックUnity Technologies Japan K.K.
 
Webinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationWebinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationMongoDB
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteChris Baynes
 
Grokking TechTalk 9 - Building a realtime & offline editing service from scra...
Grokking TechTalk 9 - Building a realtime & offline editing service from scra...Grokking TechTalk 9 - Building a realtime & offline editing service from scra...
Grokking TechTalk 9 - Building a realtime & offline editing service from scra...Grokking VN
 
Migrating on premises workload to azure sql database
Migrating on premises workload to azure sql databaseMigrating on premises workload to azure sql database
Migrating on premises workload to azure sql databasePARIKSHIT SAVJANI
 

Similar to FluentMigrator - Dayton .NET - July 2023 (20)

InteropWG Intro & Vertical Programs (May. 2017)
InteropWG Intro & Vertical Programs (May. 2017)InteropWG Intro & Vertical Programs (May. 2017)
InteropWG Intro & Vertical Programs (May. 2017)
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
 
Introduction to Meteor - revised edition
Introduction to Meteor - revised editionIntroduction to Meteor - revised edition
Introduction to Meteor - revised edition
 
Data herding
Data herdingData herding
Data herding
 
Data herding
Data herdingData herding
Data herding
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional test
 
DevOpsGuys - DevOps Automation - The Good, The Bad and The Ugly
DevOpsGuys - DevOps Automation - The Good, The Bad and The UglyDevOpsGuys - DevOps Automation - The Good, The Bad and The Ugly
DevOpsGuys - DevOps Automation - The Good, The Bad and The Ugly
 
Automation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit Europe
Automation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit EuropeAutomation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit Europe
Automation: The Good, The Bad and The Ugly with DevOpsGuys - AppD Summit Europe
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
 
YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»
YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»
YEGOR MAKSYMCHUK «Using Kubernetes for organization performance tests»
 
Building a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management ApplicationBuilding a Complex, Real-Time Data Management Application
Building a Complex, Real-Time Data Management Application
 
Continuous Delivery: The Dirty Details
Continuous Delivery: The Dirty DetailsContinuous Delivery: The Dirty Details
Continuous Delivery: The Dirty Details
 
Grokking #9: Building a real-time and offline editing service with Couchbase
Grokking #9: Building a real-time and offline editing service with CouchbaseGrokking #9: Building a real-time and offline editing service with Couchbase
Grokking #9: Building a real-time and offline editing service with Couchbase
 
Free GitOps Workshop
Free GitOps WorkshopFree GitOps Workshop
Free GitOps Workshop
 
MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)
 
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
【Unite 2017 Tokyo】C#ジョブシステムによるモバイルゲームのパフォーマンス向上テクニック
 
Webinar: Performance Tuning + Optimization
Webinar: Performance Tuning + OptimizationWebinar: Performance Tuning + Optimization
Webinar: Performance Tuning + Optimization
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
Grokking TechTalk 9 - Building a realtime & offline editing service from scra...
Grokking TechTalk 9 - Building a realtime & offline editing service from scra...Grokking TechTalk 9 - Building a realtime & offline editing service from scra...
Grokking TechTalk 9 - Building a realtime & offline editing service from scra...
 
Migrating on premises workload to azure sql database
Migrating on premises workload to azure sql databaseMigrating on premises workload to azure sql database
Migrating on premises workload to azure sql database
 

More from Matthew Groves

CREAM - That Conference Austin - January 2024.pptx
CREAM - That Conference Austin - January 2024.pptxCREAM - That Conference Austin - January 2024.pptx
CREAM - That Conference Austin - January 2024.pptxMatthew Groves
 
Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - DevIntersection - December 2022Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - DevIntersection - December 2022Matthew Groves
 
Putting the SQL Back in NoSQL - October 2022 - All Things Open
Putting the SQL Back in NoSQL - October 2022 - All Things OpenPutting the SQL Back in NoSQL - October 2022 - All Things Open
Putting the SQL Back in NoSQL - October 2022 - All Things OpenMatthew Groves
 
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Cache Rules Everything Around Me - Momentum - October 2022.pptxCache Rules Everything Around Me - Momentum - October 2022.pptx
Cache Rules Everything Around Me - Momentum - October 2022.pptxMatthew Groves
 
Don't Drop ACID (July 2021)
Don't Drop ACID (July 2021)Don't Drop ACID (July 2021)
Don't Drop ACID (July 2021)Matthew Groves
 
Don't Drop ACID - Data Love - April 2021
Don't Drop ACID - Data Love - April 2021Don't Drop ACID - Data Love - April 2021
Don't Drop ACID - Data Love - April 2021Matthew Groves
 
Demystifying NoSQL - All Things Open - October 2020
Demystifying NoSQL - All Things Open - October 2020Demystifying NoSQL - All Things Open - October 2020
Demystifying NoSQL - All Things Open - October 2020Matthew Groves
 
Autonomous Microservices - Manning - July 2020
Autonomous Microservices - Manning - July 2020Autonomous Microservices - Manning - July 2020
Autonomous Microservices - Manning - July 2020Matthew Groves
 
CONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLCONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLMatthew Groves
 
JSON Data Modeling - GDG Indy - April 2020
JSON Data Modeling - GDG Indy - April 2020JSON Data Modeling - GDG Indy - April 2020
JSON Data Modeling - GDG Indy - April 2020Matthew Groves
 
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...Matthew Groves
 
Intro to SQL++ - Detroit Tech Watch - June 2019
Intro to SQL++ - Detroit Tech Watch - June 2019Intro to SQL++ - Detroit Tech Watch - June 2019
Intro to SQL++ - Detroit Tech Watch - June 2019Matthew Groves
 
Autonomous Microservices - CodeMash - January 2019
Autonomous Microservices - CodeMash - January 2019Autonomous Microservices - CodeMash - January 2019
Autonomous Microservices - CodeMash - January 2019Matthew Groves
 
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 20185 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018Matthew Groves
 
JSON Data Modeling - July 2018 - Tulsa Techfest
JSON Data Modeling - July 2018 - Tulsa TechfestJSON Data Modeling - July 2018 - Tulsa Techfest
JSON Data Modeling - July 2018 - Tulsa TechfestMatthew Groves
 
5 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 20185 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 2018Matthew Groves
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Matthew Groves
 
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...Matthew Groves
 
I Have a NoSQL toaster - DC - August 2017
I Have a NoSQL toaster - DC - August 2017I Have a NoSQL toaster - DC - August 2017
I Have a NoSQL toaster - DC - August 2017Matthew Groves
 
Querying NoSQL with SQL - KCDC - August 2017
Querying NoSQL with SQL - KCDC - August 2017Querying NoSQL with SQL - KCDC - August 2017
Querying NoSQL with SQL - KCDC - August 2017Matthew Groves
 

More from Matthew Groves (20)

CREAM - That Conference Austin - January 2024.pptx
CREAM - That Conference Austin - January 2024.pptxCREAM - That Conference Austin - January 2024.pptx
CREAM - That Conference Austin - January 2024.pptx
 
Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - DevIntersection - December 2022Cache Rules Everything Around Me - DevIntersection - December 2022
Cache Rules Everything Around Me - DevIntersection - December 2022
 
Putting the SQL Back in NoSQL - October 2022 - All Things Open
Putting the SQL Back in NoSQL - October 2022 - All Things OpenPutting the SQL Back in NoSQL - October 2022 - All Things Open
Putting the SQL Back in NoSQL - October 2022 - All Things Open
 
Cache Rules Everything Around Me - Momentum - October 2022.pptx
Cache Rules Everything Around Me - Momentum - October 2022.pptxCache Rules Everything Around Me - Momentum - October 2022.pptx
Cache Rules Everything Around Me - Momentum - October 2022.pptx
 
Don't Drop ACID (July 2021)
Don't Drop ACID (July 2021)Don't Drop ACID (July 2021)
Don't Drop ACID (July 2021)
 
Don't Drop ACID - Data Love - April 2021
Don't Drop ACID - Data Love - April 2021Don't Drop ACID - Data Love - April 2021
Don't Drop ACID - Data Love - April 2021
 
Demystifying NoSQL - All Things Open - October 2020
Demystifying NoSQL - All Things Open - October 2020Demystifying NoSQL - All Things Open - October 2020
Demystifying NoSQL - All Things Open - October 2020
 
Autonomous Microservices - Manning - July 2020
Autonomous Microservices - Manning - July 2020Autonomous Microservices - Manning - July 2020
Autonomous Microservices - Manning - July 2020
 
CONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQLCONDG April 23 2020 - Baskar Rao - GraphQL
CONDG April 23 2020 - Baskar Rao - GraphQL
 
JSON Data Modeling - GDG Indy - April 2020
JSON Data Modeling - GDG Indy - April 2020JSON Data Modeling - GDG Indy - April 2020
JSON Data Modeling - GDG Indy - April 2020
 
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
Background Tasks Without a Separate Service: Hangfire for ASP.NET - KCDC - Ju...
 
Intro to SQL++ - Detroit Tech Watch - June 2019
Intro to SQL++ - Detroit Tech Watch - June 2019Intro to SQL++ - Detroit Tech Watch - June 2019
Intro to SQL++ - Detroit Tech Watch - June 2019
 
Autonomous Microservices - CodeMash - January 2019
Autonomous Microservices - CodeMash - January 2019Autonomous Microservices - CodeMash - January 2019
Autonomous Microservices - CodeMash - January 2019
 
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 20185 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
5 Popular Choices for NoSQL on a Microsoft Platform - Tulsa - July 2018
 
JSON Data Modeling - July 2018 - Tulsa Techfest
JSON Data Modeling - July 2018 - Tulsa TechfestJSON Data Modeling - July 2018 - Tulsa Techfest
JSON Data Modeling - July 2018 - Tulsa Techfest
 
5 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 20185 NoSQL Options - Toronto - May 2018
5 NoSQL Options - Toronto - May 2018
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
5 Popular Choices for NoSQL on a Microsoft Platform - All Things Open - Octob...
 
I Have a NoSQL toaster - DC - August 2017
I Have a NoSQL toaster - DC - August 2017I Have a NoSQL toaster - DC - August 2017
I Have a NoSQL toaster - DC - August 2017
 
Querying NoSQL with SQL - KCDC - August 2017
Querying NoSQL with SQL - KCDC - August 2017Querying NoSQL with SQL - KCDC - August 2017
Querying NoSQL with SQL - KCDC - August 2017
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

FluentMigrator - Dayton .NET - July 2023

  • 1. To Put Your Schema in Git July 2023 Matthew D. Groves | DevRel Engineer Using Fluent Migrations
  • 3. 3 Who am I? • Matthew D. Groves • Couchbase, DevRel Engineer • Author (Manning, Apress, Pluralsight) • Streamer: https://twitch.tv/matthewdgroves • https://twitter.com/mgroves • C# Advent creator
  • 4. To Put Your Schema in Git August 2023 Matthew D. Groves | DevRel Engineer Using Fluent Migrations
  • 5. 01/ 02/ 03/ 04/ 05/ 06/ Intro Why (Fluent) Migration? Demo Select Features Why NOT use it? NoSQL Agenda 07/ Next Steps
  • 6. 6 2 Why (Fluent) Migration?
  • 10. 10 What is Migration? 1. Write a script to make change(s) to a database schema • E.g. "create a table" or "alter a table" 2. Script generally corresponds to a feature change in the code base 3. Commit the script with the feature change to source control 4. Run all scripts one-by-one and/or compile all scripts into a single script NOT migration of data from one database to another
  • 11. 11 Why use Migration? • Version Control 📂⏰ • Automation ⚙⏰ • Documentation 📄📕 • Collaboration ⏰👥
  • 12. 12 Why use FluentMigrator? • 💡 Fluent, intuitive. Discoverable API • 🔗C# / .NET • 🌐 Database independence • ⏰ Automation Create.Slide("BulletPoints").With("Emojis")
  • 14. Demo
  • 16. 16 using FluentMigrator; using System; namespace YourCompany.YourProduct.Database.Maintenance { public class TagNames { public const string Development = nameof(Development); } [Tags(TagNames.Development)] [Maintenance(MigrationStage.BeforeAll, TransactionBehavior.None)] public class DevBeforeAll : ForwardOnlyMigration { public override void Up() { System.Console.WriteLine($"Tag=[{TagNames.Development}] Stage=[{MigrationStage.BeforeAll}]"); } } } Maintenance Migrations Run Logic Every Time
  • 17. 17 [Tags("DK", "NL", "UK")] [Tags("Staging", "Production")] [Migration(1)] public class DoSomeStuffToEuropeanStagingAndProdDbs : Migration { /* ... etc ... */ } Tags Filtering Migrations
  • 18. 18 /// <summary> /// Mark all migrations with this INSTEAD of [Migration]. /// </summary> public class MyCustomMigrationAttribute : FluentMigrator.MigrationAttribute { public MyCustomMigrationAttribute(int branchNumber, int year, int month, int day, int hour, int minute, string author) : base(CalculateValue(branchNumber, year, month, day, hour, minute)) { this.Author = author; } public string Author { get; private set; } private static long CalculateValue(int branchNumber, int year, int month, int day, int hour, int minute) { return branchNumber * 1000000000000L + year * 100000000L + month * 1000000L + day * 10000L + hour * 100L + minute; } } [MyCustomMigration(author: "Scott Stafford", branchNumber: 12, year: 2012, month: 8, day: 7, hour: 14, minute: 01)] public class TestLcmpMigration : Migration { public override void Down() { /* ... */ } public override void Up() { /* ... */ } } Enforce Version Numbering One Standard for the Whole Team
  • 19. 19 public class YourConventionSet : IConventionSet { public YourConventionSet() : this(new DefaultConventionSet()) { } public YourConventionSet(IConventionSet innerConventionSet) { ForeignKeyConventions = new List<IForeignKeyConvention>() { /* This is where you do your stuff */ new YourCustomDefaultForeignKeyNameConvention(), innerConventionSet.SchemaConvention, }; ColumnsConventions = innerConventionSet.ColumnsConventions; ConstraintConventions = innerConventionSet.ConstraintConventions; IndexConventions = innerConventionSet.IndexConventions; SequenceConventions = innerConventionSet.SequenceConventions; AutoNameConventions = innerConventionSet.AutoNameConventions; SchemaConvention = innerConventionSet.SchemaConvention; RootPathConvention = innerConventionSet.RootPathConvention; } /// ... etc ... } Naming Conventions What if my tables are named with GIANT_SNAKE_CASE?
  • 20. 20 [Migration(201207080104)] public class RenameTableWithSchema : AutoReversingMigration { public override void Up() { Rename.Table("TestTable2") .InSchema("TestSchema") .To("TestTable'3"); } } Auto-Reversing Such a Down()er
  • 21. 21 dotnet-fm migrate -m Session -p sqlserver2012 -c "<connection string here>" -a "./path/to/YourMigrations.dll" Transactions Begin / Commit / Rollback
  • 22. 22 5 Why NOT use it?
  • 23. 23 Top 5 Reasons NOT to use Fluent Migrator Number 3 will SHOCK you
  • 24. 24 Why NOT use FluentMigrator? 1. 💧 All Abstractions are leaky 5 Reasons
  • 25. 25 Why NOT use FluentMigrator? 1. 💧 All Abstractions are leaky 2. ⏰It's C#. How does your DBA feel about it? 5 Reasons
  • 26. 26 Why NOT use FluentMigrator? 1. 💧 All Abstractions are leaky 2. ⏰ It's C#. How does your DBA feel about it? 3. ⚙ Sprocs / views / triggers 5 Reasons
  • 27. 27 Why NOT use FluentMigrator? 1. 💧 All Abstractions are leaky 2. ⏰ It's C#. How does your DBA feel about it? 3. ⚙ Sprocs / views / triggers 4. ♊Potential duplication of concerns 5 Reasons
  • 28. 28 Why NOT use FluentMigrator? 1. 💧 All Abstractions are leaky 2. ⏰ It's C#. How does your DBA feel about it? 3. ⚙ Sprocs / views / triggers 4. ♊Potential duplication of concerns 5. 🎯 Database-specific features 5 Reasons
  • 30. 30 Couchbase is a JSON database NoSQL = No schema, right?
  • 31. 31 Couchbase is a JSON database NoSQL = No schema, right?
  • 32. 32 Couchbase is a JSON database SQL Server Couchbase Note Server Cluster ➕ Scalability / High Availability / Built-in caching Catalog (Database) Bucket Schema Scope Often just "dbo" in SQL Server or "_default" in Couchbase Table Collection ➖ Pre-defined columns/constraints Row Document ➕ Flexible JSON tSQL SQL++ (Previously known as N1QL in Couchbase) Primary Key Document Key ➖ Compound keys ➖ "No" keys Index Index
  • 33. 33 NoSQL Support for Fluent Migrator? Instead of Create.Table(. . .) what if there was Create.Collection(. . .) ?
  • 35. 35 [Migration(1)] public class Migration001_CreateInitialScopeAndCollection : Migrate { public override void Up() { Create.Scope("myScope") .WithCollection("myCollection1"); } public override void Down() { Delete.Scope("myScope"); } } NoSqlMigrator in Action Look familiar?
  • 37. 37 Try FluentMigrator • https://github.com/mgroves/FluentMigratorDemo • https://fluentmigrator.github.io/ • dotnet add package FluentMigrator How to get started
  • 38. 38 Try Couchbase Capella • Free Playground: https://couchbase.live • Free Trial (no credit card needed!) • https://www.couchbase.com/products/capella/ • Ask me about Couchbase!
  • 39. 39 Tell Someone! • Hashtag it: #DaytonDotNet? #GemCityTech? • #Couchbase • https://twitter.com/mgroves • Tell your team! • Write, make a video, podcast, etc! • https://csadvent.christmas Learn something interesting?