Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
FluentMigratorでDBマイグレーション
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
thinkAmi
February 21, 2015
Programming
0
2.3k
FluentMigratorでDBマイグレーション
2015/2/21に開かれた、めとべや東京 #7 でのLTスライドです。
thinkAmi
February 21, 2015
Tweet
Share
More Decks by thinkAmi
See All by thinkAmi
知ろう!使おう!HDF5ファイル!/pycon-jp-2019-talk
thinkami
5
11k
Djangoでのメール送信 - 設定からテストまで/djangocongress-jp-2019-talk
thinkami
1
13k
Django・WSGIミドルウェア入門/django-congress-jp-2018-talk
thinkami
4
5.5k
自分のための機械学習をしてみた話
thinkami
0
670
Xamarinで作るAndroid Wearアプリ
thinkami
1
2.7k
デプロイボタンを使ってみた
thinkami
0
1.1k
Vagrant + Berkshelf でお手軽写経環境構築
thinkami
1
1.4k
Twilio入門
thinkami
0
1.7k
おひとりさま環境でのChef-solo使用例
thinkami
2
1.5k
Other Decks in Programming
See All in Programming
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
330
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
650
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
230
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1.1k
今からFlash開発できるわけないじゃん、ムリムリ! (※ムリじゃなかった!?)
arkw
0
150
条件判定に名前、つけてますか? #phperkaigi #c
77web
2
810
20260320登壇資料
pharct
0
120
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
6
1.1k
Windows on Ryzen and I
seosoft
0
390
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
Vuetify 3 → 4 何が変わった?差分と移行ポイント10分まとめ
koukimiura
0
190
Understanding Apache Lucene - More than just full-text search
spinscale
0
140
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
590
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
120
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
200
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.3k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
86
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.1k
[SF Ruby Conf 2025] Rails X
palkan
2
860
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.5k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
100
Transcript
FluentMigratorで DBマイグレーション @thinkAmi めとべや東京 #7 2015.2.21
自己紹介 • 長野県から来ました • アカウント – thinkAmi • Twitter •
Hatena • GitHub • C#(WPF)とかMS AccessとかRubyとか
自己紹介 • りんご食べあるき – 現在57種類くらい • 今日はピンクレディを食べました • Twitter +
Heroku + C#(Ruby)で記録・公開 » http://ringo-tabetter-cs.herokuapp.com/
長野県のコミュニティ • NSEG (#nseg) – 長野県とコンピューターをテーマに毎月開催 • 本日、ギークラボ長野でOpenDataハッカソン中 • Google
Developer Group 信州 • 3/14 AndroidWearイベント » IT勉強会スタンプラリー参加 • Azure しなの (3/28 Hokuriku.NETと合同勉強会) • JAWS-UG 長野支部 » 他のコミュニティ > https://github.com/nseg- jp/w/wiki/NSEG以外の長野のIT勉強会
本題 • FluentMigratorでDBマイグレーション • クライアントアプリの裏側ということで...
定義 • DBマイグレーションとは – DBのテーブルスキーマの更新などを管理・実 行できるようにすること – 他にもありますが、今回は上記の定義です
本題 • データベースの管理にて – 最初のうち • CUIでDDLやDMLを実行 • GUIでポチポチ –
次第に忘れ去られ... • どの順番でどのDDLやDMLを実行する? • 何でこんなスキーマにしたんだっけ? » ツライ – DBマイグレーションをしたい...
Entity Framework • Code First Migrations – MS Accessで試したが使えず... •
EFがOLEDB接続をサポートしていないため » http://stackoverflow.com/a/11197393
FluentMigrator • DBマイグレーションフレームワーク – C#で、DDLやDMLを書く • DBに依存せず、スキーマの変更を記述可能 • Gitなどで、バージョン管理可能 •
リポジトリ(GitHub) – https://github.com/schambers/fluentmigrator • 830starほど • Apache 2 License
動作RDBMS • SQL Server • SQL Server Compact Edition •
PostgreSQL • MySQL • Oracle • SQLite • Jet (MS Access, ACEも動作) » https://github.com/schambers/fluentmigrator /wiki/Fluent-Interface
実行方法 • コマンドライン • NAnt • MSBuild • Rake –
Ruby + Albacore gem が必要 » https://github.com/schambers/fluentmigrator /wiki/Migration-Runners
インストール • NuGetでインストール – 本体 • PM> Install-Package FluentMigrator –
コマンドラインランナーを使う場合 • PM> Install-Package FluentMigrator.Tools
マイグレーションファイル • コード
マイグレーションの実行 • 実行 .\Migrate.exe --assembly=FluentMigrationTest.exe --provider=jet --connection="Provider=Microsoft.ACE.OLEDB.12.0;DataSo urce=D:\db\targetdb.accdb" --verbose=True --task=migrate
実行結果の表示 CREATE TABLE [hoge] ([id] COUNTER NOT NULL, [content] VARCHAR(255),
CONSTRAINT [PK_hoge] PRIMARY KEY ([id]))
MS Accessの結果 • DDLが実行されている
マイグレーション(DDL) • CREATE TABLE Create.Table("hoge") .WithColumn("id") .AsInt32() .PrimaryKey().Identity() .WithColumn("content") .AsString().Nullable();
マイグレーション(DDL) • ALTER TABLE Alter.Table("hoge") .AddColumn("fuga") .AsString().Nullable() .AlterColumn("content") .AsString().NotNullable();
マイグレーション(DDL) • CREATE INDEX Create.Index("idx") .OnTable("hoge") .OnColumn("content");
マイグレーション(DDL) • RENAME COLUMN Rename.Column("fuga") .OnTable("hoge") .To("piyo");
マイグレーション(DML) • INSERT Insert.IntoTable("hoge") .Row(new { content = "added" });
• UPDATE Update.Table("hoge") .Set(new { content = "updated" }) .Where(new { id = 1 });
ランナーのオプション – assembly » 対象のマイグレーションが含まれるexe/dll – provider » 対象のRDBMS –
connection (接続文字列) – task » Migration, Rollback(全件, 1件, 指定ver etc) – verbose » Trueでマイグレーションの詳細を表示
クラウド(Paas)での実行 • Azure Websites – 管理画面(Kudu)のConsoleにて • Heroku – Third-Party
Buildpacksでビルド • Monoでのビルド – friism/heroku-buildpack-mono – heroku/dotnet-buildpack (ASP.NET 5用?) – One-Off Dynos でHeroku Postgresへ実行 • heroku run bash 後
まとめ • FluentMigratorを使えば、EFを使えない 環境でもDBマイグレーション可能 • 他のDBマイグレーションツールがあれば 知りたいです!
参考文献など • 参考文献 – FluentMigrator公式Wikiが一番参考になります • https://github.com/schambers/fluentmigrator/wiki • スライドまわり –
プレゼンツール • Rabbit (Ruby製) – http://rabbit-shocker.org/ja/ – スライドテンプレート • 交差点の真ん中で様のパワーポイント用自作デザインテンプレート – http://sagittarius.dip.jp/toshi/template.php – フォント • フォントな様のやさしさゴシックボールド – http://www.fontna.com/blog/736/