From db68377d4250823784bac670cbb5972a5713b2cb Mon Sep 17 00:00:00 2001 From: crespire Date: Sun, 8 Dec 2024 21:41:53 -0500 Subject: [PATCH 1/6] Update macOS instructions to use Postgres.app --- .../installing_psql.md | 104 ++---------------- 1 file changed, 7 insertions(+), 97 deletions(-) diff --git a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md index 3fe73c76206..0e4dc012ad4 100644 --- a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md +++ b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md @@ -194,114 +194,24 @@ brew upgrade If your terminal doesn't recognize `brew`, then you'll need to go and install homebrew. You can find it and other installs in the [installation appendix](https://www.theodinproject.com/guides/installations). -### Step 2: Install the PostgreSQL packages - -Now that we've ensured our packages are up to date, we will use brew to install PostgreSQL. - -```bash -brew install postgresql@14 -``` - -After installation is complete, let's start the server using this command: - -```bash -brew services start postgresql@14 -``` - -If you are unsure about whether `postgresql` is active, it's possible to check with this command: - -```bash -brew services info postgresql@14 -``` - -Got an error, or don't see an active service? Come visit [our Discord server](https://discord.gg/fbFCkYabZB) for some help! - -If the `postgresql` service is active, move on to the next step. - -### Step 3: Setting up PostgreSQL +### Step 2: Install PostgreSQL via PostgresApp -PostgreSQL is now running, but we have to configure it in order to be able to use it with our local Rails applications. +Installing PostgreSQL via Postgres.app is simple. Visit [Postgres.app](https://postgresapp.com/) and follow the instructions outlined. Importantly, you'll want to configure your `$PATH` so you can access the tooling that comes along with PostgreSQL. -#### 3.1 PostgreSQL roles +Please note that that Postgres.app installs servers without any security configured, and will accept all local connections without a password. This is fine for our development environment, but be aware that when you move things to production, this will not be a good strategy. -PostgreSQL authenticates via roles. A role is like a user, and by default, the install on MacOS should have a role set up with your MacOS username. If you're not sure of your username, you can run the command `whoami` in your terminal to get it. To verify that you have a role in PostgreSQL matching your username, enter the following command: - -```bash -psql postgres -``` - -And you should see a prompt like this - -```sql -psql (14.x (Homebrew)) -Type "help" for help. - -postgres=# -``` - -Input `\du`, hit Return, and check that your MacOS username is the listed role name. - -#### 3.2 Creating the role database - -One other important step in setting up PostgreSQL is that each role must have its own database of the same name. We need this to login as the role matching our username. While still in the PostgreSQL session prompt, type the following command to create the new database. Make sure you include the semicolon. - -
- -If your username has any capital letters, you must surround it in quotes when running the below command. - -
- -```sql -CREATE DATABASE ; -``` - -Now our role is fully set up: we've got `` and that role has a database. Enter the command `\q` to exit the interactive terminal for `postgres`. - -#### 3.3 Securing Our new role - -One important thing we have to do is set up a password for our new role to protect the data. Now that we have our role, we can use it to administer PostgreSQL. All you have to do is enter this command to get into the PostgreSQL prompt for the database matching your user: +Postgres.app defaults to creating a role and user database that matches your macOS user. You can confirm this by running this command after installing Postgres.app and updating the path: ```bash psql ``` -You should now see the PostgreSQL prompt come up like this: - -```sql -role_name=# -``` - -If you don't see a similar prompt, then reach out in [our Discord server](https://discord.gg/fbFCkYabZB) for some help. If you **do** see a similar prompt, then we can create a password for the role like so: - -```sql -\password -``` - -You'll be prompted to enter a password and to verify it. Once you are done, the prompt will return to normal. Now, we will configure the permissions for our new role (note the semicolon at the end): - -```sql -GRANT ALL PRIVILEGES ON DATABASE TO ; -``` - -Remember that you should change the `` and `` (they should both be the same)! If you see `GRANT` in response to the command, then you can type `\q` to exit the prompt. - -#### 3.4 Saving access information in the environment - -After finishing our configuration, the last step is save it into the environment to access later. - -In order to save our password to the environment, we can run this command: - +You should see the PostgreSQL prompt come up like this: ```bash -echo 'export DATABASE_PASSWORD=""' >> ~/.zshrc +=# ``` -Note here the name we've chosen for our environment variable: `DATABASE_PASSWORD`. Also, remember to update `` in the command to what was set above! - -Now, this variable lives in our environment for us to use. As the variable is new, we'll want to reload the environment so that we can access it. To reload the environment, you can close and re-open your terminal. - -Once that's done, we can move to testing it out! - - +Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. ### Creating a Rails application backed by PostgreSQL From 4ac7849ecb37be4bad53585ecc77a2dfa18e6345 Mon Sep 17 00:00:00 2001 From: crespire Date: Sun, 8 Dec 2024 21:48:59 -0500 Subject: [PATCH 2/6] Add instructions to check that path is updated --- .../installing_psql.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md index 0e4dc012ad4..e8bde514524 100644 --- a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md +++ b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md @@ -198,6 +198,19 @@ If your terminal doesn't recognize `brew`, then you'll need to go and install ho Installing PostgreSQL via Postgres.app is simple. Visit [Postgres.app](https://postgresapp.com/) and follow the instructions outlined. Importantly, you'll want to configure your `$PATH` so you can access the tooling that comes along with PostgreSQL. +You can run this command to update your path: +```bash +sudo mkdir -p /etc/paths.d && +echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp +``` + +After you've run this command and restarted your terminal, you can run `which psql` and we would expect this output: +```bash +/Applications/Postgres.app/Contents/Versions/latest/bin/psql +``` + +If you don't see a similar output, come visit [our Discord server](https://discord.gg/fbFCkYabZB) for some help! + Please note that that Postgres.app installs servers without any security configured, and will accept all local connections without a password. This is fine for our development environment, but be aware that when you move things to production, this will not be a good strategy. Postgres.app defaults to creating a role and user database that matches your macOS user. You can confirm this by running this command after installing Postgres.app and updating the path: @@ -211,7 +224,7 @@ You should see the PostgreSQL prompt come up like this: =# ``` -Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. +Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. ### Creating a Rails application backed by PostgreSQL From f0e0c627731a54106d1ab55ebb80f595a9d813e9 Mon Sep 17 00:00:00 2001 From: crespire Date: Sun, 8 Dec 2024 21:54:14 -0500 Subject: [PATCH 3/6] Close details tag --- .../advanced_forms_and_activerecord/installing_psql.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md index e8bde514524..d72af4ecdfd 100644 --- a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md +++ b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md @@ -226,6 +226,8 @@ You should see the PostgreSQL prompt come up like this: Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. + + ### Creating a Rails application backed by PostgreSQL Now that we've installed and configured our local PostgreSQL server, let's generate a new Rails application to make sure everything is working. From 7fd7a58db1f01e1c99487c3f4a8e24be1aa8b612 Mon Sep 17 00:00:00 2001 From: crespire Date: Sun, 8 Dec 2024 21:54:33 -0500 Subject: [PATCH 4/6] Replicate changes to nodeJS lesson --- nodeJS/express/installing_postgresql.md | 99 +++---------------------- 1 file changed, 12 insertions(+), 87 deletions(-) diff --git a/nodeJS/express/installing_postgresql.md b/nodeJS/express/installing_postgresql.md index 2d5572a5127..0c43dffa591 100644 --- a/nodeJS/express/installing_postgresql.md +++ b/nodeJS/express/installing_postgresql.md @@ -172,110 +172,35 @@ If your terminal doesn't recognize `brew`, then you'll need to go and install ho ### Step 2: Install the PostgreSQL packages -Now that we've ensured our packages are up to date, we will use brew to install PostgreSQL. +Installing PostgreSQL via Postgres.app is simple. Visit [Postgres.app](https://postgresapp.com/) and follow the instructions outlined. Importantly, you'll want to configure your `$PATH` so you can access the tooling that comes along with PostgreSQL. +You can run this command to update your path: ```bash -brew install postgresql@14 +sudo mkdir -p /etc/paths.d && +echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp ``` -After installation is complete, let's start the server using this command: - -```bash -brew services start postgresql@14 -``` - -If you are unsure about whether `postgresql` is active, it's possible to check with this command: - +After you've run this command and restarted your terminal, you can run `which psql` and we would expect this output: ```bash -brew services info postgresql@14 +/Applications/Postgres.app/Contents/Versions/latest/bin/psql ``` -Got an error, or don't see an active service? Come visit the [Discord](https://discord.gg/V75WSQG) for some help! - -If the `postgresql` service is active, move on to the next step. - -### Step 3: Setting up PostgreSQL - -PostgreSQL is now running, but we have to configure it in order to be able to use it with our local Express applications. +If you don't see a similar output, come visit [our Discord server](https://discord.gg/fbFCkYabZB) for some help! -#### 3.1 PostgreSQL roles +Please note that that Postgres.app installs servers without any security configured, and will accept all local connections without a password. This is fine for our development environment, but be aware that when you move things to production, this will not be a good strategy. -PostgreSQL authenticates via roles. A role is like a user, and by default, the install on MacOS should have a role set up with your MacOS username. If you're not sure of your username, you can run the command `whoami` in your terminal to get it. To verify that you have a role in PostgreSQL matching your username, enter the following command: - -```bash -psql postgres -``` - -And you should see a prompt like this - -```sql -psql (14.x (Homebrew)) -Type "help" for help. - -postgres=# -``` - -Input `\du`, hit Return, and check that your MacOS username is the listed role name. - -#### 3.2 Creating the role database - -One other important step in setting up PostgreSQL is that each role must have its own database of the same name. We need this to login as the role matching our username. While still in the PostgreSQL session prompt, type the following command to create the new database. Make sure you include the semicolon. - -
- -If your username has any capital letters, you must surround it in quotes when running the below command. - -
- -```sql -CREATE DATABASE ; -``` - -Now our role is fully set up: we've got `` and that role has a database. Enter the command `\q` to exit the interactive terminal for `postgres`. - -#### 3.3 Securing Our new role - -One important thing we have to do is set up a password for our new role to protect the data. Now that we have our role, we can use it to administer PostgreSQL. All you have to do is enter this command to get into the PostgreSQL prompt for the database matching your user: +Postgres.app defaults to creating a role and user database that matches your macOS user. You can confirm this by running this command after installing Postgres.app and updating the path: ```bash psql ``` -You should now see the PostgreSQL prompt come up like this: - -```sql -role_name=# -``` - -If you don't see a similar prompt, then reach out on [Discord](https://discord.gg/V75WSQG) for some help. If you **do** see a similar prompt, then we can create a password for the role like so: - -```sql -\password -``` - -You'll be prompted to enter a password and to verify it. Once you are done, the prompt will return to normal. Now, we will configure the permissions for our new role (note the semicolon at the end): - -```sql -GRANT ALL PRIVILEGES ON DATABASE TO ; -``` - -Remember that you should change the `` and `` (they should both be the same)! If you see `GRANT` in response to the command, then you can type `\q` to exit the prompt. - -#### 3.4 Saving access information in the environment - -After finishing our configuration, the last step is save it into the environment to access later. - -In order to save our password to the environment, we can run this command: - +You should see the PostgreSQL prompt come up like this: ```bash -echo 'export DATABASE_PASSWORD=""' >> ~/.zshrc +=# ``` -Note here the name we've chosen for our environment variable: `DATABASE_PASSWORD`. Also, remember to update `` in the command to what was set above! - -Now, this variable lives in our environment for us to use. As the variable is new, we'll want to reload the environment so that we can access it. To reload the environment, you can close and re-open your terminal. - -Once that's done, we can move to testing it out! +Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. From 71fa4aee10d61ba4202f3c91b5276d3c627b69ac Mon Sep 17 00:00:00 2001 From: crespire Date: Sun, 8 Dec 2024 21:58:26 -0500 Subject: [PATCH 5/6] Add additional text to exit psql tool --- nodeJS/express/installing_postgresql.md | 2 +- .../advanced_forms_and_activerecord/installing_psql.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nodeJS/express/installing_postgresql.md b/nodeJS/express/installing_postgresql.md index 0c43dffa591..a6e3ae8343c 100644 --- a/nodeJS/express/installing_postgresql.md +++ b/nodeJS/express/installing_postgresql.md @@ -200,7 +200,7 @@ You should see the PostgreSQL prompt come up like this: =# ``` -Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. +Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. You can type `\q` to exit. diff --git a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md index d72af4ecdfd..8e92e66c525 100644 --- a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md +++ b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md @@ -224,7 +224,7 @@ You should see the PostgreSQL prompt come up like this: =# ``` -Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. +Because Postgres.app has configured trusted authentication for all local connections, we don't need to set up any password authentication for our local development environment. Just remember that your `role_name` is the user that appears in the `psql` prompt above. You can type `\q` to exit. From bb4d7055f7470c62792755be79f274aadbd13c17 Mon Sep 17 00:00:00 2001 From: crespire Date: Sun, 8 Dec 2024 22:02:19 -0500 Subject: [PATCH 6/6] Linter fix --- nodeJS/express/installing_postgresql.md | 5 ++++- .../advanced_forms_and_activerecord/installing_psql.md | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nodeJS/express/installing_postgresql.md b/nodeJS/express/installing_postgresql.md index a6e3ae8343c..6fc5335c994 100644 --- a/nodeJS/express/installing_postgresql.md +++ b/nodeJS/express/installing_postgresql.md @@ -175,12 +175,14 @@ If your terminal doesn't recognize `brew`, then you'll need to go and install ho Installing PostgreSQL via Postgres.app is simple. Visit [Postgres.app](https://postgresapp.com/) and follow the instructions outlined. Importantly, you'll want to configure your `$PATH` so you can access the tooling that comes along with PostgreSQL. You can run this command to update your path: -```bash + + ```bash sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp ``` After you've run this command and restarted your terminal, you can run `which psql` and we would expect this output: + ```bash /Applications/Postgres.app/Contents/Versions/latest/bin/psql ``` @@ -196,6 +198,7 @@ psql ``` You should see the PostgreSQL prompt come up like this: + ```bash =# ``` diff --git a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md index 8e92e66c525..f13199e5684 100644 --- a/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md +++ b/ruby_on_rails/advanced_forms_and_activerecord/installing_psql.md @@ -199,13 +199,15 @@ If your terminal doesn't recognize `brew`, then you'll need to go and install ho Installing PostgreSQL via Postgres.app is simple. Visit [Postgres.app](https://postgresapp.com/) and follow the instructions outlined. Importantly, you'll want to configure your `$PATH` so you can access the tooling that comes along with PostgreSQL. You can run this command to update your path: -```bash + + ```bash sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp ``` After you've run this command and restarted your terminal, you can run `which psql` and we would expect this output: -```bash + + ```bash /Applications/Postgres.app/Contents/Versions/latest/bin/psql ``` @@ -220,6 +222,7 @@ psql ``` You should see the PostgreSQL prompt come up like this: + ```bash =# ```