Skip to content
This repository was archived by the owner on Mar 10, 2021. It is now read-only.

Commit 85bb9fd

Browse files
Merge pull request #35 from infinitered/update/indexes
Expand page title and description, add indexes
2 parents e4baab6 + 87951d6 commit 85bb9fd

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

lib/mix/tasks/thesis.install.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff 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
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

0 commit comments

Comments
 (0)