Bootcamp
Search…
3.ICE.8: Multiple Foreign Keys

Introduction

Create a command-line app for an art museum. The museum curators develop collections for paintings to be part of. Collection names can reflect their school, art movement, years, or donors. For example, a collection might have the name "The New York School: Art and Mania" and contain 2 paintings from the New York School. A different collection could have the name "The Cubist Epoch" and contain 3 Cubist paintings. Collections can contain paintings by different artists. A painting is credited to a single artist, and can only be part of 1 collection at a time.

Base

DB Setup

  1. 1.
    Create a new database called museum.
  2. 2.
    Create 3 tables: artists, collections and paintings. Record the CREATE TABLE statements in a file init_tables.sql for debugging purposes.

App Setup

  1. 1.
    Begin with the base Node repo.​
  2. 2.
    Install the pg library with NPM.
  3. 3.
    Use the code from 3.4.2: PostgreSQL Node App as a template for index.js. Remember to update pgConnectionConfigs to reference the new DB name.

Insert Seed Data

The museum is mounting 2 shows, 1 on the New York School and 1 on Cubism. Use the links to populate the database by writing INSERT queries for each table. Note that the exercises below assume that the tables have been pre-populated.

Create Painting and Add to Collection

Command Template

1
node index.js new-painting <PAINTING_NAME> <ARTIST_ID> <COLLECTION_ID>
Copied!

Sample Command

This command assumes "Henri Matisse" has artist ID 2 and the collection you intend to place the painting in has ID 3.
1
node index.js new-painting 'Marguerite' 2 3
Copied!

Get Artists in the Collection

Command Template

1
node index.js get-artists <COLLECTION_NAME>
Copied!

Sample Command

This command assumes you've named the Cubism collection "The Cubism Show" in the database.
1
node index.js get-artists 'The Cubism Show'
Copied!
1
1. Picasso
2
2. Max Weber
3
3. Georges Braque
Copied!

Comfortable

Create New Collection and Move Paintings into It

The museum is mounting a new show. Put paintings that the museum already has into the new collection.

Command Template

1
node index.js new-collection <COLLECTION_NAME> <PAINTING_ID> [<PAINTING_ID> ...]
Copied!

Sample Command

This command assumes that paintings 'Girls of Avignon' and 'Marguerite' already exist in the DB with IDs 1 and 2 respectively.
1
node index.js new-collection 'Paris in 1907' 1 2
Copied!

More Comfortable

Create Painting and Add to Collection (with Artist and Collection Names)

Command Template

1
node index.js new-painting <PAINTING_NAME> <ARTIST_NAME> <COLLECTION_NAME>
Copied!

Sample Command

1
node index.js new-painting 'Yellow, Cherry, Orange' 'Mark Rothko' 'The New York School'
Copied!