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

An in-depth look at database migrations & seedi...

An in-depth look at database migrations & seeding in Laravel

From the presentation presented at the Laravel Chicago PHP UG on February 23rd, 2016: http://www.meetup.com/laravel-chicago/events/228116711/

Sammy Kaye Powers

February 23, 2016
Tweet

More Decks by Sammy Kaye Powers

Other Decks in Technology

Transcript

  1. Deployment $ cd /path/to/repo $ git remote add production \

    dancer-app:/path/to/example.com/git $ git push production \ +master:refs/heads/master
  2. Old School Method CREATE TABLE `users` ( `id` int(10) unsigned

    NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `password` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `users_email_unique` (`email`) ) ENGINE=InnoDB;
  3. Old School Method INSERT INTO `users` (`id`, `name`, `email`, `password`)

    VALUES (1,'Jane Doe','[email protected]','test123'), (2,'Jon Doe','[email protected]','jon123'); should be hashed
  4. Old School Method INSERT INTO `users` (`id`, `name`, `email`, `password`)

    VALUES (1,'Jane Doe','[email protected]','test123'), (2,'Jon Doe','[email protected]','jon123'); should be hashed MD5
  5. Old School Method INSERT INTO `users` (`id`, `name`, `email`, `password`)

    VALUES (1,'Jane Doe','[email protected]','test123'), (2,'Jon Doe','[email protected]','jon123'); should be hashed MD5
  6. Old School Method INSERT INTO `users` (`id`, `name`, `email`, `password`)

    VALUES (1,'Jane Doe','[email protected]','test123'), (2,'Jon Doe','[email protected]','jon123'); should be hashed MD5
  7. Old School Method INSERT INTO `users` (`id`, `name`, `email`, `password`)

    VALUES (1,'Jane Doe','[email protected]','test123'), (2,'Jon Doe','[email protected]','jon123'); should be hashed MD5 +
  8. $ git add README.md $ git commit -m “Update docs”

    $ git push production Old School Method Ship IT!
  9. Laravel Way CREATE TABLE `users` ( `id` int(10) unsigned NOT

    NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `password` varchar(60) COLLATE utf8_unicode_ci NOT NULL, `remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `created_at` timestamp NULL DEFAULT NULL, `updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `users_email_unique` (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  10. Laravel Way $ php artisan migrate Old School Method CREATE

    TABLE `users` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `email` varchar(255) NOT NULL, `password` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `users_email_unique` (`email`) ) ENGINE=InnoDB;
  11. Old School Method INSERT INTO `users` (`id`, `name`, `email`, `password`)

    VALUES (1,'Jane Doe','[email protected]','test123'), (2,'Jon Doe','[email protected]','jon123'); Remember When…
  12. $ git add README.md $ git commit -m “Update docs”

    $ git push production Ship IT! Laravel Way
  13. $ git add README.md $ git commit -m “Update docs”

    $ git push production Ship IT! Laravel Way Wait!
  14. Deployment #!/bin/bash app_root=‘/path/to/example.com/http/' echo "Updating public files..." GIT_WORK_TREE=$app_root git checkout

    -f echo "Updating the database..." php ${app_root}artisan migrate --force echo "Installing composer packages..." cd $app_root composer install echo "Done!"
  15. $ git add README.md $ git commit -m “Update docs”

    $ git push production Ship IT! Laravel Way
  16. Watch me open source! “It is recommended to store the

    result in a database column that can expand beyond 60 characters (255 characters would be a good choice).” password_hash()