From e224eee89fc9ec20fd64bd4b1f3a14d87f2ed678 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 31 May 2021 20:24:50 -0400 Subject: [PATCH] FREAKING HUGE MYSQL IN DEV YAK SHAVE --- .env | 4 ++- README.md | 86 ++++++++++++++++++++++++++++++++++++++++++++++------- src/main.rs | 2 +- 3 files changed, 79 insertions(+), 13 deletions(-) diff --git a/.env b/.env index e7f1c54d72..e0c2972a6a 100644 --- a/.env +++ b/.env @@ -1,4 +1,6 @@ -DATABASE_URL=mysql://root:root@localhost/storyteller +DATABASE_URL=mysql://storyteller:password@localhost/storyteller +#DATABASE_URL=mysql://root:root@localhost/storyteller +#DATABASE_URL=mysql://root@localhost/storyteller # SQLX normally requires a live database to reflect upon at build time. # This setting turns that on and requires a `sql-data.json` cache file instead. diff --git a/README.md b/README.md index e8ccd9d054..a60ae3382b 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,19 @@ This is our main user account monolith that we'll also bake other pieces into. Local development ----------------- +### Setup + +Install diesel, + +``` +sudo apt-get install libmysqlclient-dev +cargo install diesel_cli --no-default-features --features mysql +``` + +If MySql in local dev can't be connected to, reset the accounts: + +https://linuxconfig.org/how-to-reset-root-mysql-mariadb-password-on-ubuntu-20-04-focal-fossa-linux + ### Database migrations To reset the entire database (drop, migrate), run: @@ -13,13 +26,13 @@ To reset the entire database (drop, migrate), run: diesel database reset ``` -To migrate at the current step and beyond: +To migrate at the current step and beyond: ``` diesel migration run ``` -To undo migrations at the current step: +To undo migrations at the current step: ``` diesel migration redo @@ -77,9 +90,9 @@ TODO Notes / TODOs: -* Examples for good Actix+Sqlx Tests: +* Examples for good Actix+Sqlx Tests: https://stackoverflow.com/questions/65370752/how-do-i-create-an-actix-web-server-that-accepts-both-sqlx-database-pools-and-tr - + * Actix/sqlx runtime compat: https://github.com/launchbadge/sqlx/issues/1117#issuecomment-801237734 @@ -91,7 +104,7 @@ The repository needs to be given read access to the base docker image: https://github.com/orgs/storytold/packages/container/docker-base-images-rust-ssl/settings -Local Nginx Proxy +Local Nginx Proxy ----------------- Set up a local nginx to proxy to the frontend and backend so cookie issues aren't annoying @@ -99,23 +112,74 @@ Edit, `/etc/nginx/sites-enabled/storyteller` ``` server { - listen 80; + listen 80; server_name api.jungle.horse; - location / { + location / { proxy_set_header Host $host; proxy_pass http://127.0.0.1:12345; proxy_redirect off; - } + } } server { - listen 80; + listen 80; server_name jungle.horse; - location / { + location / { proxy_set_header Host $host; proxy_pass http://127.0.0.1:7000; proxy_redirect off; - } + } } ``` +Fixing dev MySql on Ubuntu 20.04 +-------------------------------- + +For some reason, the MySql default install on 20.04 gave me a bunch of trouble. + +In retrospect, I _think_ this is because 'root@localhost' requires sudo to access, but if this +gives any trouble in the future, here's how I got around it (two full hours of distraction!) + + +``` +sudo apt-get install mysql-server + +# But for some reason the default password doesn't work and diesel/sqlx can't connect? + +# Kill everything + +sudo apt purge mysql-server mysql-client mysql-common +sudo apt autoremove +sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup +sudo rm -rf /var/lib/mysql* + +sudo /usr/bin/mysql_secure_installation + +# still no work... + +sudo systemctl stop mysql.service + +# ugh, it wasn't chowned or created (both states observed in different installs)… +sudo mkdir -p /var/run/mysqld +sudo chown mysql:mysql /var/run/mysqld + +sudo mysqld_safe --skip-grant-tables --skip-networking & + +mysql -u root + +flush privileges; +USE mysql; +ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; + +sudo killall -u mysql +sudo systemctl restart mysql.service + +# now it works +sudo mysql -u root -p + +# but now I have to use "sudo" !?!? + +CREATE USER 'storyteller'@'localhost' IDENTIFIED BY 'password'; +GRANT ALL PRIVILEGES ON storyteller.* TO 'storyteller'@'localhost'; +``` + diff --git a/src/main.rs b/src/main.rs index 3aa3640461..94c1947892 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,7 +109,7 @@ async fn main() -> AnyhowResult<()> { let db_connection_string = easyenv::get_env_string_or_default( "MYSQL_URL", - "mysql://root:root@localhost/storyteller"); + "mysql://storyteller:password@localhost/storyteller"); let pool = MySqlPoolOptions::new() .max_connections(5)