Is there a way to change the default database instance from Postgres to Mariadb or Mysql for ecto? I am aware of the option to use the database flag, but since I have years more experience with mysql, I’d love to make it the default.
I do not believe that there is any kind of config file or anything that you could set to make your choice of database the default. I think that generally the generators are only used once when creating a project, so I’m not sure that adding such an option would be all that beneficial. If you are in fact creating new Phoenix projects on the regular you could always create a bash script which passes the flags you would like.
Take a look at the docs for
mix phx.new: mix phx.new — Phoenix v1.5.9
You can simply specify the
--database mysql option when creating a new Phoenix project.
You can always make some kind of shell alias if You really want to avoid typing –database mysql.
But You cannot change default value of phx.new
You could, however, fork it and make your own version to change the default and install your fork locally. ^.^
Seems like it would be a pretty minimal patchset to keep in sync. Maybe even PR it looking in a config in
$XDG_CONFIG_HOME somewhere for what default config options for it to set (don’t forget to log to user that it found a config file at a given location and is using it for defaults so it’s not silently surprising).
Yes, forking is a possibility
Yes, but I think I’m too much of an Elixir virgin and not ready to fork…
I am at the stage where I am running several tutorials and wondering whether I am better off biting the bullet and using Postgres for now or figure out how to modify the scripts that call mix setup or phx.new to make it use MySQL.
It’s mainly the Postgres shell that makes me slow and unhappy. Maybe I’ll try a gui for Postgres and see if that works around the issue.
Thanks for your feedback, all.
I would recommend to use postgresql if You want to follow tutorials, because there are some differences with mysql. Almost all tutorials I saw use it.
like ordering, or search case sensitivity, or extensions (citext, postgis etc).
I have often used mysql with Rails, but once I had to use windows functions. I don’t know if it is supported by mysql now, but 5 years ago it was not.
It’s always possible to switch later.
I would recommend using postgres, I started with MySQL and while it worked fine, there was a subset of ecto features that I wanted to use which required using postgres. Though switching from mysql to postgres was relatively painless all things considered, so if you do decide to go with one and then change your mind it should be doable. But yeah I wouldn’t bother modifying the script for phx.new, just use the --database flag or like I said earlier, wrap it in a bash script.
In case it’s of interest, in the last 2 or 3 years windowed functions and other features like virtual columns have received significant upgrades on Mariadb and MySQL, with little functionality missing compared to MSSQL for example. Although Mariadb is usually ahead of the curve.