Blog: Migration
Mix.install([
{:jason, "~> 1.4"},
{:kino, "~> 0.9", override: true},
{:youtube, github: "brooklinjazz/youtube"},
{:hidden_cell, github: "brooklinjazz/hidden_cell"}
])
Navigation
Home Report An Issue Schemas And MigrationsBook Search: BooksBlog: Migration
Your existing Blog application should already have blog posts with a title, subtitle, and content.
Blog Post Migration
You’re going to create a migration or many migrations to modify the blog posts table with the following changes:
-
Remove the
subtitlefield -
Add a
published_on:datefield. -
Add a
visible:booleanfield which defaults totrue.
Ensure your Post schema reflects these changes, and ensure all tests pass. Modify existing tests to include the new fields.
Ensure all features of your application such as creating, reading, updating, and deleting posts continue to work. You will likely need to modify any pages using old fields that are no longer valid.
Form Fields
Add a date input for the published_on field, and a checkbox input for the visible field.
Use the IEx shell to view all Post records to ensure your form correctly creates a blog post.
iex -S mix
Visibility
When displaying a list of blog posts, hide any blog posts whose visible field is false or whose published_on field is after the current UTC date.
Push To GitHub
From the blog folder run the following commands.
First, ensure that all tests pass.
mix test
Then create a pull request, review it, and merge it into your main branch.
Bonus: Constraints
Create another migration to add the following constraints:
- Modify the title field to be unique.
-
Modify the
titleso it must be between3and100characters.
Ensure your Post schema reflects these constraints and validations.
Commit Your Progress
DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.
Run git status to ensure there are no undesirable changes.
Then run the following in your command line from the curriculum folder to commit your progress.
$ git add .
$ git commit -m "finish Blog: Migration exercise"
$ git push
We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.
We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.