Skip to content

Instantly share code, notes, and snippets.

@MateusAquino
Created August 6, 2022 15:05
Show Gist options
  • Save MateusAquino/adcc8829edc66bc8424dc1dfb5afa922 to your computer and use it in GitHub Desktop.
Save MateusAquino/adcc8829edc66bc8424dc1dfb5afa922 to your computer and use it in GitHub Desktop.

Elixir Logo DB (script)

Esse é um script para rodar alguns comandos do postgres + ecto :thumbsup-parrot:

Requisitos

Esse script requer 🎀 gum!

Scripts

Você deve colocar as funções abaixo no seu .zshrc ou em um arquivo separado para usar o db:

function ecto() {
  if [[ $1 = "reset"  ]]; then
    if [[ $2 = "dev" ]] || [[ $2 = "both" ]]; then
      mix ecto.drop && mix ecto.create && mix ecto.migrate
    fi
    if [[ $2 = "test" ]] || [[ $2 = "both" ]]; then
      MIX_ENV=test mix ecto.drop && MIX_ENV=test mix ecto.create && MIX_ENV=test mix ecto.migrate
    fi
  elif [[ $1 = "rollback" ]]; then
    mix ecto.rollback && MIX_ENV=test mix ecto.rollback
  elif [[ $1 = "migrate" ]]; then
    mix ecto.migrate && MIX_ENV=test mix ecto.migrate
  fi
}

function db() (
  trap 'return 1' INT
  cmd=$(gum choose "docker start postgres" "docker stop postgres" "docker rm postgres" "docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres -d postgres:13-alpine" "ecto reset dev" "ecto reset test" "ecto reset both" "ecto rollback" "ecto migrate")
  eval $cmd
)

DB (script)

Mostra lista de comandos/alias/scripts (customizavel):

USAGE:
    db

image

Ecto

Alguns scripts para realizar ações no ecto tanto em dev quanto em test.

USAGE:
    ecto [command] <opt>

COMMANDS:
    reset     Reseta o banco (drop/create/migrate) # requer opt: dev, test, both
    rollback  Faz rollback tanto de dev quanto de test
    migrate   Roda migrations tanto de dev quanto de test

EXAMPLES:
ecto reset dev
ecto reset test
ecto reset both
ecto rollback
ecto migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment