This repository was archived by the owner on Mar 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-4
lines changed
priv/templates/thesis.install Expand file tree Collapse file tree 2 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,15 @@ defmodule Mix.Tasks.Thesis.Install do
22 use Mix.Task
33 import Mix.Thesis.Utils
44
5+ @ migrations [
6+ "create_thesis_tables" ,
7+ "add_meta_to_thesis_page_contents" ,
8+ "add_indexes_to_tables"
9+ ]
10+ @ template_files [
11+ { "priv/templates/thesis.install/thesis_auth.exs" , "lib/thesis_auth.ex" }
12+ ]
13+
514 @ shortdoc "Generates Thesis code in your Phoenix app"
615
716 @ moduledoc """
@@ -29,14 +38,12 @@ defmodule Mix.Tasks.Thesis.Install do
2938 @ doc false
3039 def thesis_templates do
3140 migrations = [ "create_thesis_tables" , "add_meta_to_thesis_page_contents" ]
32- migration_files = migrations
41+ migration_files = @ migrations
3342 |> Enum . filter ( & migration_missing? / 1 )
3443 |> Enum . with_index
3544 |> Enum . map ( & migration_tuple / 1 )
3645
37- template_files = [ { "priv/templates/thesis.install/thesis_auth.exs" , "lib/thesis_auth.ex" } ]
38-
39- template_files ++ migration_files
46+ @ template_files ++ migration_files
4047 |> Stream . map ( & render_eex / 1 )
4148 |> Stream . map ( & copy_to_target / 1 )
4249 |> Stream . run
Original file line number Diff line number Diff line change 1+ defmodule <% = base % > .Repo . Migrations.AddIndexToTables do
2+ use Ecto.Migration
3+
4+ def up do
5+ alter table ( :thesis_pages ) do
6+ modify :title , :string , size: 512
7+ modify :description , :string , size: 1024
8+ end
9+
10+ # Index page slugs, since we're searching on those
11+ create index ( :thesis_pages , [ :slug ] )
12+
13+ # Create foreign key constraint for page_contents -> page
14+ alter table ( :thesis_page_contents ) do
15+ modify :page_id , references ( :thesis_pages , on_delete: :delete_all )
16+ end
17+ end
18+
19+ def down do
20+ alter table ( :thesis_pages ) do
21+ modify :title , :string
22+ modify :description , :string
23+ end
24+
25+ remove index ( :thesis_pages , [ :slug ] )
26+ end
27+ end
You can’t perform that action at this time.
0 commit comments