Created
February 4, 2023 04:36
-
-
Save marciol/416e98c2f7459215e8a099e49331e016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mix.install([ | |
{:ecto_sql, "~> 3.7.0"}, | |
{:myxql, "~> 0.6.2"} | |
]) | |
Application.put_env(:foo, Repo, database: "app_db", | |
hostname: "db", | |
username: "app_user", | |
password: "app_pass") | |
defmodule Repo do | |
use Ecto.Repo, | |
adapter: Ecto.Adapters.MyXQL, | |
otp_app: :foo | |
end | |
defmodule Migration0 do | |
use Ecto.Migration | |
def change do | |
create table("things") do | |
add(:thing_time, :time) | |
add(:thing_time_usec, :time_usec) | |
add(:thing_naive_datetime, :naive_datetime) | |
add(:thing_naive_datetime_usec, :naive_datetime_usec) | |
add(:thing_utc_datetime, :utc_datetime) | |
add(:thing_utc_datetime_usec, :utc_datetime_usec) | |
end | |
end | |
end | |
defmodule Thing do | |
use Ecto.Schema | |
import Ecto.Changeset | |
schema "things" do | |
field(:thing_time, :time) | |
end | |
def changeset(thing, params \\ %{}) do | |
thing | |
|> cast(params, [ | |
:thing_time, | |
]) | |
|> validate_required([ | |
:thing_time, | |
]) | |
end | |
end | |
defmodule Main do | |
def main do | |
children = [ | |
Repo | |
] | |
_ = Repo.__adapter__().storage_down(Repo.config()) | |
:ok = Repo.__adapter__().storage_up(Repo.config()) | |
{:ok, _} = Supervisor.start_link(children, strategy: :one_for_one) | |
current_time = ~T[00:00:00] | |
Ecto.Migrator.run(Repo, [{0, Migration0}], :up, all: true, log_sql: :debug) | |
Repo.insert!(%Thing{ | |
thing_time: current_time, | |
}) | |
IO.inspect(Repo.all(Thing)) | |
end | |
end | |
Main.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
db: | |
platform: linux/x86_64 | |
image: mysql:5.7.38 | |
environment: | |
MYSQL_ROOT_PASSWORD: root_pass | |
MYSQL_DATABASE: app_db | |
MYSQL_USER: app_user | |
MYSQL_PASSWORD: app_pass | |
ports: | |
- "3306:3306" | |
app: | |
build: . | |
command: elixir app/app.ex | |
volumes: | |
- .:/app | |
depends_on: | |
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM hexpm/elixir:1.13.4-erlang-24.3.4.2-debian-stretch-20210902 | |
RUN apt-get update && \ | |
apt-get install -y postgresql-client && \ | |
mix local.hex --force && \ | |
mix local.rebar --force | |
ENV APP_HOME /app | |
RUN mkdir $APP_HOME | |
WORKDIR $APP_HOME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment