Skip to content

Instantly share code, notes, and snippets.

@ray-sh
Last active August 26, 2021 03:34
Show Gist options
  • Save ray-sh/8bf8b2f0466d089da2b6ee6344082751 to your computer and use it in GitHub Desktop.
Save ray-sh/8bf8b2f0466d089da2b6ee6344082751 to your computer and use it in GitHub Desktop.
#start psql
psql postgres
# list all databases
\l
#connect the db
\c db_name
#list all tables
\dt
#get all schemals
select schema_name from information_schema.schemata;
#migrations under one schemal, schemal_name will be public if not specified
select * from schema_name.schema_migrations;
#run migration in runtime
alias YourAppName.Repo
your_app_name_as_atom = :test
downto_version = 20170724182558
# Down:
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :down, [to: downto_version])
# Up:
This will run migration for user jack. This is very import for multitanlant saas application
Ecto.Migrator.run(Repo, "priv/repo/migrations/", :up, [all: true, prefix: "jack"])
# In production when not sure if working directory is inside app dir:
Ecto.Migrator.run(Repo, Application.app_dir(your_app_name_as_atom, "priv/repo/migrations"), :down, [to: downto_version])
Ecto.Migrator.run(Repo, Application.app_dir(your_app_name_as_atom, "priv/repo/migrations"), :up, [all: true])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment