![]() Step 2 - Creating a Database Role for Your Application Once PostgreSQL is installed, the next step is to create a role that your Rails application will use later to create your database. To start the service and enable it to start at login, run the following:Ĭheck to make sure the installation was successful: Then, apply the changes you made to your ~/.bash_profile file to your current shell session: echo 'export 10/bin:$PATH"' > ~/.bash_profile.Next, include the PostgreSQL binary in your PATH variable in order to access the PostgreSQL command line tools, making sure to replace the 10 with the version number you are using: You can find the available packages at the Homebrew website. If you would like to download a specific version of PostgreSQL, replace postgresql in the previous command with your desired package. To install the latest version, run the following command: ![]() There are multiple Homebrew packages to install different versions of PostgreSQL. Although there are many ways to install PostgreSQL on macOS, this tutorial will use the package manager Homebrew. In order to configure Ruby on Rails to create your web application with PostgreSQL as a database, you will first install the database onto your machine. This tutorial will use version 2.6.3 of Ruby and 5.2.3 of Rails for information on the latest versions, check out the official sites for Ruby and Rails. To set this up, follow our guide on How To Install Ruby on Rails with rbenv on macOS. This tutorial has been tested on macOS 10.14 Mojave.Ī Ruby on Rails development environment installed on your macOS machine. One computer or virtual machine with macOS installed, with administrative access to that machine and an internet connection. You will install and configure PostgreSQL, and then test your setup by creating a Rails application that uses PostgreSQL as its database server. In this tutorial, you will set up a Ruby on Rails development environment connected to a PostgreSQL database on a local macOS machine. ![]() In order to configure your Ruby on Rails setup to use PostgreSQL, you will need to perform a few additional steps to get it up and running. However, for highly complex applications that need more reliable data integrity and programmatic extensibility, a PostgreSQL database will be a more robust and flexible choice. SQLite is a lightweight, portable, and user-friendly relational database that performs especially well in low-memory environments, and will work well in many cases. The result will show up below.When using the Ruby on Rails web framework, your application is set up by default to use SQLite as a database. Pick your database by clicking the little database icon, selecting your database, and clicking OK.Īfter you’ve picked your database, click the little SQL box, type in your query, and click Run Current. Running SQL queries against a Postgres database in TablePlus The data will import, fill up your new database, and you’ll be all set! sql file you’re interested in, click OK, and click OK again to run the import.įor the mondial data, you’ll import the schema file first, and the import second. Technically this isn’t a SQL dump, its just a bunch of SQL commands, but I’m not going to complain! To import a SQL file, select File > Import > From SQL Dump. You probably want to do this with a newly created database (see previous step). Importing SQL to a new databse using TablePlus Give your database a name, and click OK to finish. Once you’re connected, you can create a new table by clicking the database button, then the +. If you’re on a mac, make sure you’ve opened Postgres.app. If you get an error like the one below, it’s because your server isn’t running. Open up TablePlus and follow the instructions to create a new connection (right click + New > Connection).Īll of the defaults should be ok, although type in a password if you set one (on Windows it forces you to set one! Maybe you used your computer password?). Connecting TablePlus to your Postgres server You should be able to do all of your important with psql, but just in case you have weird issues - character encoding is a big one - you can use TablePlus (you downloaded this as prep already). Using TablePlus to create and query Postgres databases
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |