Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Writing Readable Migrations with Nextras Migrations

Writing Readable Migrations with Nextras Migrations

Jan Tvrdík

October 12, 2017
Tweet

More Decks by Jan Tvrdík

Other Decks in Programming

Transcript

  1. queries wrapped in strings strings wrapped in method calls method

    calls wrapped in a method body method body wrapped in a class
  2. 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
  3. 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
  4. 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 | +---------+----------+---------------------+----+
  5. order is strictly defined new migrations can be only at

    the end you must always „rebase“ your migrations once executed migration cannot be changed
  6. 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
  7. 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"
  8. 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"