Skip to content

Latest commit

 

History

History
91 lines (74 loc) · 2.79 KB

DatabaseSetup.md

File metadata and controls

91 lines (74 loc) · 2.79 KB

Direct to SwiftUI Database Setup

Setting up PostgreSQL

Using Homebrew

brew install PostgreSQL
brew services start postgresql # start at computer start
createuser -s postgres

Using Postgres.app

Download and install Postgres.app, a nice UI wrapper to manage PostgreSQL databases.

Loading the dvdrental DB

curl -o /tmp/dvdrental.zip \
  http://www.postgresqltutorial.com/wp-content/uploads/2019/05/dvdrental.zip
mkdir -p /tmp/dvdrental && cd /tmp/dvdrental
tar zxf /tmp/dvdrental.zip
tar xf  /tmp/dvdrental.tar # crazy, right?
createdb dvdrental
pg_restore -h localhost -U postgres -d dvdrental .
$ psql -h localhost -U postgres dvdrental
psql (11.4)
Type "help" for help.

dvdrental=# \dt
             List of relations
 Schema |     Name      | Type  |  Owner   
--------+---------------+-------+----------
 public | actor         | table | postgres
 public | address       | table | postgres
 public | category      | table | postgres
 public | city          | table | postgres
 public | country       | table | postgres
 public | customer      | table | postgres
 public | film          | table | postgres
 public | film_actor    | table | postgres
 public | film_category | table | postgres
 public | inventory     | table | postgres
 public | language      | table | postgres
 public | payment       | table | postgres
 public | rental        | table | postgres
 public | staff         | table | postgres
 public | store         | table | postgres
(15 rows)

Make a Backup Copy

To create a backup copy of your database, run:

CREATE DATABASE dvdrental_org TEMPLATE dvdrental;

Setting up SQLite dvdrental (Sakila)

cd /tmp
wget https://raw.githubusercontent.com/jOOQ/jOOQ/master/jOOQ-examples/Sakila/sqlite-sakila-db/sqlite-sakila-schema.sql
wget https://raw.githubusercontent.com/jOOQ/jOOQ/master/jOOQ-examples/Sakila/sqlite-sakila-db/sqlite-sakila-insert-data.sql
sqlite3 dvdrental.sqlite3 < sqlite-sakila-schema.sql
sqlite3 dvdrental.sqlite3 < sqlite-sakila-insert-data.sql
sqlite3 dvdrental.sqlite3
sqlite> .tables
actor                   film                    payment               
address                 film_actor              rental                
category                film_category           sales_by_film_category
city                    film_list               sales_by_store        
country                 film_text               staff                 
customer                inventory               staff_list            
customer_list           language                store