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
Writing Readable Migrations with Nextras Migrat...
Search
Jan Tvrdík
October 12, 2017
Programming
120
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Writing Readable Migrations with Nextras Migrations
Jan Tvrdík
October 12, 2017
More Decks by Jan Tvrdík
See All by Jan Tvrdík
Runtime Types in TypeScript
jantvrdik
0
60
How to Write Parser in PHP
jantvrdik
0
100
Nextras Mail Panel
jantvrdik
0
170
Writing reliable migrations with Nextras Migrations
jantvrdik
1
710
Other Decks in Programming
See All in Programming
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
260
Webフレームワークの ベンチマークについて
yusukebe
0
140
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.5k
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
190
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
120
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
3.2k
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.9k
The NotImplementedError Problem in Ruby
koic
1
640
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
220
AIエージェントと協働するCLI開発 — BunとOpenClawで学んだこと
yoshikouki
1
240
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
230
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
110
Featured
See All Featured
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
310
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
How to build a perfect <img>
jonoalderson
1
5.6k
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
430
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
190
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
720
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
220
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
300
Being A Developer After 40
akosma
91
590k
How to Think Like a Performance Engineer
csswizardry
28
2.6k
Code Review Best Practice
trishagee
74
20k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Transcript
Jan Tvrdík
None
but not limited to database snapshot approach mostly not usable
delta approach is hard to get right
None
None
None
None
None
Business Critical Code
doctrine:migrations:diff \ --formatted
None
None
queries wrapped in strings strings wrapped in method calls method
calls wrapped in a method body method body wrapped in a class
let's give each migration a descriptive name let's make the
content match the name let's remove all the noise by using SQL
None
None
easy to write code completion works well easy to format
„Reformat Code“ just works easy to read no noise & well formatted easy to test „Run“ just works „Copy & Paste“ just works no limitations
migrations/ ├── 001.sql ├── 002.sql └── ... +---------+----------+---------------------+----+ | file
| checksum | executed | ok | +---------+----------+---------------------+----+ | 001.sql | 78634... | 2015-08-28 17:05:03 | 1 | | 002.sql | dda40... | 2015-08-28 17:05:03 | 1 | | 003.sql | 5b9c6... | 2015-08-28 17:05:03 | 1 | +---------+----------+---------------------+----+
order is strictly defined new migrations can be only at
the end you must always „rebase“ your migrations once executed migration cannot be changed
migrations/ ├── structures/ │ ├── 2015-07-21-170126-init.sql │ └── 2015-07-22-144133-photo-description.sql ├──
basic-data/ │ └── ... └── dummy-data/ └── ...
S B P D L Structures Basic data Dummy data
Production Localhost
structures DDL only + DML required for DDL basic data
DML for tables in 2 (countries, languages…) dummy data for testing app on localhost w/o strict rules because not used on production
Symfony commands migrations:continue migrations:reset migrations:create
simple web interface when CLI is not available
PHP 5.4+ databases PostgreSQL MySQL DBALs Nextras DBAL Nette Database
Doctrine DBAL dibi
SQL executes all queries in *.sql file PHP for complex
migrations
extensions: migrations: Nextras\Migrations\Bridges\NetteDI\MigrationsExtension migrations: dir: %appDir%/../migrations # base directory driver:
pgsql # pgsql or mysql dbal: doctrine # nextras, nette, doctrine or dibi diffGenerator: doctrine ignoredQueriesFile: "%appDir%/../migrations/ignored.sql"
new \Nextras\Migrations\Bridges\SymfonyBundle\NextrasMigrationsBundle(); nextras_migrations: dir: "%kernel.root_dir%/migrations" driver: pgsql # pgsql or
mysql dbal: nextras # nextras, nette, doctrine or dibi diff_generator: doctrine ignored_queries_file: "%kernel.root_dir%/migrations/ignored.sql"
https://github.com/nextras/migrations https://nextras.org/migrations/docs/
Twitter + GitHub @JanTvrdik nextras.org