-
-
Save keekerdc/4a2cbdc058f966962732a573c7356e93 to your computer and use it in GitHub Desktop.
Connecting to PlanetScale DB from Phoenix (elixir)
This file contains hidden or 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
# config/dev.exs | |
# Now running migrations will be: PSCALE=1 mix ecto.migrate | |
db_name = if System.get_env("PSCALE"), do: "db_name", else: "db_name_dev" | |
db_hostname = if System.get_env("PSCALE"), do: "127.0.0.1", else: "localhost" | |
db_port = if System.get_env("PSCALE"), do: 3305, else: 3306 | |
# Configure your database | |
config :db_name, db_name.Repo, | |
username: "root", | |
password: "", | |
database: db_name, | |
hostname: db_hostname, | |
port: db_port, | |
show_sensitive_data_on_connection_error: true, | |
pool_size: 10 |
This file contains hidden or 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
database_name = | |
System.get_env("DATABASE_NAME") || | |
raise """ | |
environment variable DATABASE_NAME is missing. | |
For example: my_db_name (see planetscale connection guides) | |
""" | |
database_hostname = | |
System.get_env("DATABASE_HOSTNAME") || | |
raise """ | |
environment variable DATABASE_HOSTNAME is missing. | |
For example: random-hostname.region.psdb.cloud (see planetscale connection guides) | |
""" | |
database_username = | |
System.get_env("DATABASE_USERNAME") || | |
raise """ | |
environment variable DATABASE_USERNAME is missing. | |
For example: ie83n0neoerr (see planetscale connection guides) | |
""" | |
database_password = | |
System.get_env("DATABASE_PASSWORD") || | |
raise """ | |
environment variable DATABASE_PASSWORD is missing. | |
For example: pscale_pw_ceT0k5mVVzi4GWPPyOaFORbpf4yGsf (see planetscale connection guides) | |
""" | |
config :db_name, AppName.Repo, | |
username: database_username, | |
database: database_name, | |
hostname: database_hostname, | |
password: database_password, | |
ssl: true, | |
ssl_opts: [ | |
verify: :verify_peer, | |
cacertfile: CAStore.file_path(), | |
server_name_indication: String.to_charlist(database_hostname), | |
customize_hostname_check: [ | |
match_fun: :public_key.pkix_verify_hostname_match_fun(:https) | |
] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment