Skip to content

Instantly share code, notes, and snippets.

@BenMorganIO
Created October 6, 2018 01:50
Show Gist options
  • Save BenMorganIO/582910aedf1cf093d16083215ce6eee8 to your computer and use it in GitHub Desktop.
Save BenMorganIO/582910aedf1cf093d16083215ce6eee8 to your computer and use it in GitHub Desktop.
defmodule Test do
def migrations_for(migration_source) when is_binary(migration_source) do
query = Path.join(migration_source, "*")
for entry <- Path.wildcard(query),
info = extract_migration_info(entry),
do: info
end
defp extract_migration_info(file) do
base = Path.basename(file)
ext = Path.extname(base)
case Integer.parse(Path.rootname(base)) do
{integer, "_" <> name} when ext == ".exs" ->
{integer, name, file}
_ ->
nil
end
end
end
1..4 |>
Task.async_stream(fn id ->
repo = Ocelot.Repo
Apartmentex.TenantActions.create_schema(repo, id)
migration_path = Apartmentex.MigrationsPathBuilder.tenant_migrations_path(repo)
# Ecto.Migrator.run(repo, migration_path, :up, all: true, prefix: "store_#{id}")
opts = [all: true, prefix: "store_#{id}"]
Ecto.Migration.SchemaMigration.ensure_schema_migrations_table!(repo, opts[:prefix])
versions = Ecto.Migration.SchemaMigration.migrated_versions(repo, opts[:prefix])
migrations =
migration_path |>
Test.migrations_for |>
Enum.filter(fn {version, _name, _file} -> not (version in versions) end)
# Enum.map(migrations)
IO.inspect Code.loaded_files
Enum.map migrations, fn {version, name_or_mod, file} ->
IO.inspect file
modules = Code.eval_file(file)
IO.inspect modules
mod = Enum.at(modules, 0)
# do_up(repo, version, mod, opts)
IO.inspect version
end
end) |>
Enum.to_list
1..4 |> Task.async_stream(fn id -> Apartmentex.drop_tenant(Ocelot.Repo, id) end) |> Enum.to_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment