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

Commit

Permalink
Merge pull request #35 from infinitered/update/indexes
Browse files Browse the repository at this point in the history
Expand page title and description, add indexes
  • Loading branch information
jamonholmgren authored Jul 20, 2016
2 parents e4baab6 + 87951d6 commit 85bb9fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/mix/tasks/thesis.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ defmodule Mix.Tasks.Thesis.Install do
use Mix.Task
import Mix.Thesis.Utils

@migrations [
"create_thesis_tables",
"add_meta_to_thesis_page_contents",
"add_indexes_to_tables"
]
@template_files [
{"priv/templates/thesis.install/thesis_auth.exs", "lib/thesis_auth.ex" }
]

@shortdoc "Generates Thesis code in your Phoenix app"

@moduledoc """
Expand Down Expand Up @@ -29,14 +38,12 @@ defmodule Mix.Tasks.Thesis.Install do
@doc false
def thesis_templates do
migrations = ["create_thesis_tables", "add_meta_to_thesis_page_contents"]
migration_files = migrations
migration_files = @migrations
|> Enum.filter(&migration_missing?/1)
|> Enum.with_index
|> Enum.map(&migration_tuple/1)

template_files = [ {"priv/templates/thesis.install/thesis_auth.exs", "lib/thesis_auth.ex" } ]

template_files ++ migration_files
@template_files ++ migration_files
|> Stream.map(&render_eex/1)
|> Stream.map(&copy_to_target/1)
|> Stream.run
Expand Down
27 changes: 27 additions & 0 deletions priv/templates/thesis.install/add_indexes_to_tables.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule <%= base %>.Repo.Migrations.AddIndexToTables do
use Ecto.Migration

def up do
alter table(:thesis_pages) do
modify :title, :string, size: 512
modify :description, :string, size: 1024
end

# Index page slugs, since we're searching on those
create index(:thesis_pages, [:slug])

# Create foreign key constraint for page_contents -> page
alter table(:thesis_page_contents) do
modify :page_id, references(:thesis_pages, on_delete: :delete_all)
end
end

def down do
alter table(:thesis_pages) do
modify :title, :string
modify :description, :string
end

remove index(:thesis_pages, [:slug])
end
end

0 comments on commit 85bb9fd

Please # to comment.