forked from shibao/cannery
		
	improve migrations
This commit is contained in:
		@@ -2,10 +2,6 @@ defmodule Cannery.Repo.Migrations.RenameTypeToClass do
 | 
				
			|||||||
  use Ecto.Migration
 | 
					  use Ecto.Migration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def up do
 | 
					  def up do
 | 
				
			||||||
    drop index(:ammo_types, [:type])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    flush()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rename table(:ammo_types), :type, to: :class
 | 
					    rename table(:ammo_types), :type, to: :class
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    alter table(:ammo_types) do
 | 
					    alter table(:ammo_types) do
 | 
				
			||||||
@@ -14,8 +10,6 @@ defmodule Cannery.Repo.Migrations.RenameTypeToClass do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    flush()
 | 
					    flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    create index(:ammo_types, [:class])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    execute """
 | 
					    execute """
 | 
				
			||||||
    ALTER TABLE ammo_types
 | 
					    ALTER TABLE ammo_types
 | 
				
			||||||
      ADD COLUMN search tsvector
 | 
					      ADD COLUMN search tsvector
 | 
				
			||||||
@@ -59,10 +53,6 @@ defmodule Cannery.Repo.Migrations.RenameTypeToClass do
 | 
				
			|||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def down do
 | 
					  def down do
 | 
				
			||||||
    drop index(:ammo_types, [:class])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    flush()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rename table(:ammo_types), :class, to: :type
 | 
					    rename table(:ammo_types), :class, to: :type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    alter table(:ammo_types) do
 | 
					    alter table(:ammo_types) do
 | 
				
			||||||
@@ -71,8 +61,6 @@ defmodule Cannery.Repo.Migrations.RenameTypeToClass do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    flush()
 | 
					    flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    create index(:ammo_types, [:type])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    execute """
 | 
					    execute """
 | 
				
			||||||
    ALTER TABLE ammo_types
 | 
					    ALTER TABLE ammo_types
 | 
				
			||||||
      ADD COLUMN search TSVECTOR
 | 
					      ADD COLUMN search TSVECTOR
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ defmodule Cannery.Repo.Migrations.RenameAmmoGroupsToPacks do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  def up do
 | 
					  def up do
 | 
				
			||||||
    drop index(:ammo_groups, [:user_id], where: "count = 0", name: :empty_ammo_groups_index)
 | 
					    drop index(:ammo_groups, [:user_id], where: "count = 0", name: :empty_ammo_groups_index)
 | 
				
			||||||
 | 
					    drop index(:shot_groups, [:user_id, :ammo_group_id])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    flush()
 | 
					    flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -25,5 +26,9 @@ defmodule Cannery.Repo.Migrations.RenameAmmoGroupsToPacks do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    create index(:ammo_groups, [:user_id], where: "count = 0", name: :empty_ammo_groups_index)
 | 
					    create index(:ammo_groups, [:user_id], where: "count = 0", name: :empty_ammo_groups_index)
 | 
				
			||||||
    rename table(:shot_groups), :pack_id, to: :ammo_group_id
 | 
					    rename table(:shot_groups), :pack_id, to: :ammo_group_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    flush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    create index(:shot_groups, [:user_id, :ammo_group_id])
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,19 +1,7 @@
 | 
				
			|||||||
defmodule Cannery.Repo.Migrations.RenameShotGroupsToShotRecords do
 | 
					defmodule Cannery.Repo.Migrations.RenameShotGroupsToShotRecords do
 | 
				
			||||||
  use Ecto.Migration
 | 
					  use Ecto.Migration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def up do
 | 
					  def change do
 | 
				
			||||||
    drop index(:shot_groups, [:user_id, :pack_id])
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    flush()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    rename table(:shot_groups), to: table(:shot_records)
 | 
					    rename table(:shot_groups), to: table(:shot_records)
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					 | 
				
			||||||
  def down do
 | 
					 | 
				
			||||||
    rename table(:shot_records), to: table(:shot_groups)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    flush()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    create index(:shot_groups, [:user_id, :pack_id])
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user