Number Guessing Game - Build a Number Guessing Game

Tell us what’s happening:

I can’t output what’s asked,

even though (I think) I’ve already done it.

Your code so far
##################SHELL SCRIPT:##################

#!/bin/bash

PSQL="psql --username=freecodecamp --dbname=number_guess -t --no-align -c"

MAIN_MENU(){

  echo "Enter your username:"
  read USERNAME

  #if valid input
  if [[ $USERNAME =~ ^[a-zA-Z]{0,22}$ ]]
  then
    # get user_id
    USER_ID=$($PSQL "SELECT user_id FROM users WHERE username='$USERNAME'")

    # if user_id does not exits (user_id is empty)
    if [[ -z $USER_ID ]]
    then
      #print welcome to new user
      echo "Welcome, $USERNAME! It looks like this is your first time here."
      
      # this is the guessing game
      SECRET_NUMBER=$(echo $(( $RANDOM % 1000 + 1 )))

      echo "Guess the secret number between 1 and 1000:"
      read GUESS
      
      # add new user to database
      INSERT_NEW_USER=$($PSQL "INSERT INTO users (username) VALUES ('$USERNAME')")
      USER_ID=$($PSQL "SELECT user_id FROM users WHERE username='$USERNAME'")

      # insert new game
      INSERT_NEW_GAME=$($PSQL "INSERT INTO games (user_id) VALUES ($USER_ID)")
      GAME_ID=$($PSQL "SELECT MAX(game_id) FROM games;")

      COUNT=1
      
      # if not a number
      if [[ $GUESS =~ ^[0-9]+$ ]]
      then
        GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
      else
        echo That is not an integer, guess again:
      fi

    # if user exists
    else
      # get number of games played
      GAMES_PLAYED=$($PSQL "SELECT MAX(games_played) FROM games INNER JOIN users USING (user_id) WHERE user_id=$USER_ID")

      # get best game of the user
      BEST_GAME=$($PSQL "SELECT MIN(gd.number_of_guesses) FROM game_description gd INNER JOIN games g USING (game_id) INNER JOIN users u USING (user_id) WHERE u.user_id=$USER_ID")

      # print welcome to user
      echo -e "\nWelcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."

      # this is the guessing game
      SECRET_NUMBER=$(echo $(( $RANDOM % 1000 + 1 )))
      #echo $SECRET_NUMBER
      echo -e "\nGuess the secret number between 1 and 1000:"
      read GUESS

      # insert new game
      INSERT_NEW_GAME=$($PSQL "INSERT INTO games (user_id) VALUES ($USER_ID)")
      GAME_ID=$($PSQL "SELECT MAX(game_id) FROM games;")

      COUNT=1
      
      # if not a number
      if [[ $GUESS =~ ^[0-9]+$ ]]
      then
        GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
      else
        echo That is not an integer, guess again:
      fi
    fi

  # not a valid input
  else
    echo "Please enter a valid username. Just 22 characters."
  fi
}

GUESS_NUMBER(){
  SECRET_NUMBER=$1
  GUESS=$2
  COUNT=$3
  USER_ID=$4
  GAME_ID=$5

  while [[ $GUESS != $SECRET_NUMBER ]]
  do
    #echo "Guess #$COUNT"
    if [[ $GUESS =~ ^[0-9]+$ ]]
    then
      if [[ $GUESS > $SECRET_NUMBER ]]
      then
        echo "It's lower than that, guess again:"
        read GUESS
      elif [[ $GUESS < $SECRET_NUMBER ]]
      then
        echo "It's higher than that, guess again:"
        read GUESS
      fi
      COUNT=$(($COUNT+1))
    else
      echo "That is not an integer, guess again:"
      read GUESS
    fi
  done

  echo "You guessed it in $COUNT tries. The secret number was $SECRET_NUMBER. Nice job!"

  #get amount of games played
  GAMES_PLAYED=$($PSQL "SELECT MAX(games_played) FROM games WHERE user_id=$USER_ID")
  
  # if no games played
  if [[ -z $GAMES_PLAYED ]]
  then
    # insert first game
    INSERT_GAMES_PLAYED=$($PSQL "UPDATE games SET games_played=1 WHERE game_id=$GAME_ID AND user_id=$USER_ID")
  else
    # insert the new game
    GAMES_PLAYED=$(($GAMES_PLAYED+1))
    INSERT_GAMES_PLAYED=$($PSQL "UPDATE games SET games_played=$GAMES_PLAYED WHERE user_id=$USER_ID AND game_id=$GAME_ID")
  fi

  # insert number of guesses
  INSERT_NUMBER_OF_GUESSES=$($PSQL "INSERT INTO game_description (game_id, number_of_guesses) VALUES ($GAME_ID, $COUNT)")
}

MAIN_MENU
**#########SQL CODE /  MY DATABASE#########**
--
-- PostgreSQL database dump
--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE number_guess;
--
-- Name: number_guess; Type: DATABASE; Schema: -; Owner: freecodecamp
--

CREATE DATABASE number_guess WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';


ALTER DATABASE number_guess OWNER TO freecodecamp;

\connect number_guess

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: game_description; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.game_description (
    game_id integer,
    number_of_guesses integer
);


ALTER TABLE public.game_description OWNER TO freecodecamp;

--
-- Name: games; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.games (
    game_id integer NOT NULL,
    user_id integer,
    games_played integer
);


ALTER TABLE public.games OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.games_game_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.games_game_id_seq OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.games_game_id_seq OWNED BY public.games.game_id;


--
-- Name: users; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.users (
    user_id integer NOT NULL,
    username character varying(22),
    game_id integer
);


ALTER TABLE public.users OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.users_user_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.users_user_id_seq OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;


--
-- Name: games game_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games ALTER COLUMN game_id SET DEFAULT nextval('public.games_game_id_seq'::regclass);


--
-- Name: users user_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval('public.users_user_id_seq'::regclass);


--
-- Data for Name: game_description; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Data for Name: games; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Name: games_game_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.games_game_id_seq', 1, false);


--
-- Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.users_user_id_seq', 1, false);


--
-- Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT games_pkey PRIMARY KEY (game_id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);


--
-- Name: game_description game_description_game_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.game_description
    ADD CONSTRAINT game_description_game_id_fkey FOREIGN KEY (game_id) REFERENCES public.games(game_id);


--
-- Name: games games_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT games_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(user_id);


--
-- Name: users users_game_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_game_id_fkey FOREIGN KEY (game_id) REFERENCES public.games(game_id);


--
-- PostgreSQL database dump complete
--


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 OPR/94.0.0.0

Challenge: Number Guessing Game - Build a Number Guessing Game

Link to the challenge:

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

You have other issues that may not allow the tests to validate. (I don’t know if the test you want to pass requires other parts of the program to work first for eg).

I would work on fixing the issues I know about first then come back and see if this one remains unchecked after I am done.

Issues that I noticed include that you are not handling invalid entries correctly. A user may give you an invalid username for eg but then after you echo the message you don’t seem to allow them to renter it?
Same for the guesses. If my first guess is bad, you don’t allow me to enter another? Also you must handle invalid guesses throughout (someone can make an invalid guess at any time not just at the beginning).

Thanks! Didn’t know about this.

1 Like

Hey!

I was completely blind to the validations lol, now I have validated the inputs… and I think there should be no problem with them…

Here is my code

#!/bin/bash

PSQL="psql --username=freecodecamp --dbname=number_guess -t --no-align -c"

MAIN_MENU(){

  echo "Enter your username:"
  read USERNAME

  #if valid input
  if [[ $USERNAME =~ ^[a-zA-Z]{0,22}$ ]]
  then
    # get user_id
    USER_ID=$($PSQL "SELECT user_id FROM users WHERE username='$USERNAME'")

    # if user_id does not exits (user_id is empty)
    if [[ -z $USER_ID ]]
    then
      #print welcome to new user
      echo "Welcome, $USERNAME! It looks like this is your first time here."
      
      # this is the guessing game
      SECRET_NUMBER=$(echo $(( $RANDOM % 1000 + 1 )))
      #echo $SECRET_NUMBER
      echo "Guess the secret number between 1 and 1000:"
      read GUESS
      
      # add new user to database
      INSERT_NEW_USER=$($PSQL "INSERT INTO users (username) VALUES ('$USERNAME')")
      USER_ID=$($PSQL "SELECT user_id FROM users WHERE username='$USERNAME'")

      # insert new game
      INSERT_NEW_GAME=$($PSQL "INSERT INTO games (user_id) VALUES ($USER_ID)")
      GAME_ID=$($PSQL "SELECT MAX(game_id) FROM games;")

      COUNT=1
      
      # if not a number
      if [[ $GUESS =~ ^[0-9]+$ ]]
      then
        GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
      else
        echo "That is not an integer, guess again:"
        read GUESS
        GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
      fi

    # if user exists
    else
      # get number of games played
      GAMES_PLAYED=$($PSQL "SELECT MAX(games_played) FROM games INNER JOIN users USING (user_id) WHERE user_id=$USER_ID")

      # get best game of the user
      BEST_GAME=$($PSQL "SELECT MIN(gd.number_of_guesses) FROM game_description gd INNER JOIN games g USING (game_id) INNER JOIN users u USING (user_id) WHERE u.user_id=$USER_ID")

      # print welcome to user
      echo "Welcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."

      # this is the guessing game
      SECRET_NUMBER=$(echo $(( $RANDOM % 1000 + 1 )))
      #echo $SECRET_NUMBER
      echo "Guess the secret number between 1 and 1000:"
      read GUESS

      # insert new game
      INSERT_NEW_GAME=$($PSQL "INSERT INTO games (user_id) VALUES ($USER_ID)")
      GAME_ID=$($PSQL "SELECT MAX(game_id) FROM games;")

      COUNT=1
      
      # if not a number
      if [[ $GUESS =~ ^[0-9]+$ ]]
      then
        GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
      else
        echo "That is not an integer, guess again:"
        read GUESS
        GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
      fi
    fi

  # not a valid input
  else
    echo "Please enter a valid username. Just 22 characters."
    MAIN_MENU
  fi
}

GUESS_NUMBER(){
  SECRET_NUMBER=$1
  GUESS=$2
  COUNT=$3
  USER_ID=$4
  GAME_ID=$5

  while [[ $GUESS != $SECRET_NUMBER ]]
  do
    if [[ $GUESS =~ ^[0-9]+$ ]]
    then
      if [[ $GUESS -gt $SECRET_NUMBER ]]
      then
        if [[ $GUESS -gt 1000 ]]
        then
          echo "Guess can't be higher than 1000"
          read GUESS
        else
          echo "It's lower than that, guess again:"
          read GUESS
          COUNT=$(($COUNT+1))
        fi
      elif [[ $GUESS -lt $SECRET_NUMBER ]]
      then
        if [[ $GUESS -lt 1 ]]
        then 
          echo "Guess can't be lower than 1"
          read GUESS    
        else
          echo "It's higher than that, guess again:"
          read GUESS
          COUNT=$(($COUNT+1))
        fi
      else
        echo -e "how did I get here?\n"
        read GUESS
      fi
    else
      echo "That is not an integer, guess again:"
      read GUESS
    fi
  done

  echo "You guessed it in $COUNT tries. The secret number was $SECRET_NUMBER. Nice job!"

  #get amount of games played
  GAMES_PLAYED=$($PSQL "SELECT MAX(games_played) FROM games WHERE user_id=$USER_ID")
  
  # if no games played
  if [[ -z $GAMES_PLAYED ]]
  then
    # insert first game
    INSERT_GAMES_PLAYED=$($PSQL "UPDATE games SET games_played=1 WHERE game_id=$GAME_ID AND user_id=$USER_ID")
  else
    # insert the new game
    GAMES_PLAYED=$(($GAMES_PLAYED+1))
    INSERT_GAMES_PLAYED=$($PSQL "UPDATE games SET games_played=$GAMES_PLAYED WHERE user_id=$USER_ID AND game_id=$GAME_ID")
  fi

  # insert number of guesses
  INSERT_NUMBER_OF_GUESSES=$($PSQL "INSERT INTO game_description (game_id, number_of_guesses) VALUES ($GAME_ID, $COUNT)")
}

MAIN_MENU

The thing now, it’s that, I’ve regressed :joy: :sob:

That one was already checked before, sigh.

I was wondering where did you get the requirement to post this message?
You must only write messages as per the exercise, nothing more.

edit: actually I will also say, the validation you are doing on the username, I’m not sure was requested either? So if nothing was requested in the script for this, then I would not add that validation as it may be tripping up the test.

Can’t belieeeeeeeve haha I lost so much time just because an underscore “_”…

First:

elif [[ $USERNAME =~ ^[a-zA-Z0-9]{0,22}$ ]]

Now:

elif [[ $USERNAME =~ ^[a-zA-Z0-9_]{0,22}$ ]]

All the script

#!/bin/bash

PSQL="psql --username=freecodecamp --dbname=number_guess -t --no-align -c"

MAIN_MENU(){

  echo "Enter your username:"
  read USERNAME

  # if username is null
  if [[ -z $USERNAME ]]
  then
    echo "Empty input is not accepted. Please enter your username"
    MAIN_MENU
  valid input
  elif [[ $USERNAME =~ ^[a-zA-Z0-9_]{0,22}$ ]]
  then
    # get user_id
    USER_ID=$($PSQL "SELECT user_id FROM users WHERE username='$USERNAME'")

    # if user_id does not exits (user_id is empty)
    if [[ -z $USER_ID ]]
    then
      #print welcome to new user
      echo "Welcome, $USERNAME! It looks like this is your first time here."
      
      # this is the guessing game
      SECRET_NUMBER=$(echo $(( $RANDOM % 1000 + 1 )))
      #echo $SECRET_NUMBER
      echo "Guess the secret number between 1 and 1000:"
      read GUESS
      
      # add new user to database
      INSERT_NEW_USER=$($PSQL "INSERT INTO users (username) VALUES ('$USERNAME')")
      USER_ID=$($PSQL "SELECT user_id FROM users WHERE username='$USERNAME'")

      # insert new game
      INSERT_NEW_GAME=$($PSQL "INSERT INTO games (user_id) VALUES ($USER_ID)")
      GAME_ID=$($PSQL "SELECT MAX(game_id) FROM games;")

      COUNT=1
      
      GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID

    # if user exists
    else
      # get number of games played
      GAMES_PLAYED=$($PSQL "SELECT MAX(games_played) FROM games INNER JOIN users USING (user_id) WHERE user_id=$USER_ID")

      # get best game of the user
      BEST_GAME=$($PSQL "SELECT MIN(gd.number_of_guesses) FROM game_description gd INNER JOIN games g USING (game_id) INNER JOIN users u USING (user_id) WHERE u.user_id=$USER_ID")

      # print welcome to user
      echo "Welcome back, $USERNAME! You have played $GAMES_PLAYED games, and your best game took $BEST_GAME guesses."

      # this is the guessing game
      SECRET_NUMBER=$(echo $(( $RANDOM % 1000 + 1 )))
      #echo $SECRET_NUMBER
      echo "Guess the secret number between 1 and 1000:"
      read GUESS

      # insert new game
      INSERT_NEW_GAME=$($PSQL "INSERT INTO games (user_id) VALUES ($USER_ID)")
      GAME_ID=$($PSQL "SELECT MAX(game_id) FROM games;")

      COUNT=1
      
      GUESS_NUMBER $SECRET_NUMBER $GUESS $COUNT $USER_ID $GAME_ID
    fi
  # not a valid input
  else
    echo "Please enter a valid username. Just 22 characters."
    MAIN_MENU
  fi
}

GUESS_NUMBER(){
  SECRET_NUMBER=$1
  GUESS=$2
  COUNT=$3
  USER_ID=$4
  GAME_ID=$5

  while [[ $GUESS != $SECRET_NUMBER ]]
  do
    if [[ $GUESS =~ ^[0-9]+$ ]]
    then
      if [[ $GUESS -gt $SECRET_NUMBER ]]
      then
        echo "It's lower than that, guess again:"
        read GUESS
        COUNT=$(($COUNT+1))
      elif [[ $GUESS -lt $SECRET_NUMBER ]]
      then
        echo "It's higher than that, guess again:"
        read GUESS
        COUNT=$(($COUNT+1))
      fi
    else
      echo "That is not an integer, guess again:"
      read GUESS
    fi
  done

  echo "You guessed it in $COUNT tries. The secret number was $SECRET_NUMBER. Nice job!"

  #get amount of games played
  GAMES_PLAYED=$($PSQL "SELECT MAX(games_played) FROM games WHERE user_id=$USER_ID")
  
  # if no games played
  if [[ -z $GAMES_PLAYED ]]
  then
    # insert first game
    INSERT_GAMES_PLAYED=$($PSQL "UPDATE games SET games_played=1 WHERE game_id=$GAME_ID AND user_id=$USER_ID")
  else
    # insert the new game
    GAMES_PLAYED=$(($GAMES_PLAYED+1))
    INSERT_GAMES_PLAYED=$($PSQL "UPDATE games SET games_played=$GAMES_PLAYED WHERE user_id=$USER_ID AND game_id=$GAME_ID")
  fi

  # insert number of guesses
  INSERT_NUMBER_OF_GUESSES=$($PSQL "INSERT INTO game_description (game_id, number_of_guesses) VALUES ($GAME_ID, $COUNT)")
}

MAIN_MENU

My data base code … a bit better than the first one :slight_smile:

--
-- PostgreSQL database dump
--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

DROP DATABASE number_guess;
--
-- Name: number_guess; Type: DATABASE; Schema: -; Owner: freecodecamp
--

CREATE DATABASE number_guess WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';


ALTER DATABASE number_guess OWNER TO freecodecamp;

\connect number_guess

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: game_description; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.game_description (
    game_description_id integer NOT NULL,
    game_id integer,
    number_of_guesses integer
);


ALTER TABLE public.game_description OWNER TO freecodecamp;

--
-- Name: game_description_game_description_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.game_description_game_description_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.game_description_game_description_id_seq OWNER TO freecodecamp;

--
-- Name: game_description_game_description_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.game_description_game_description_id_seq OWNED BY public.game_description.game_description_id;


--
-- Name: games; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.games (
    game_id integer NOT NULL,
    user_id integer,
    games_played integer
);


ALTER TABLE public.games OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.games_game_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.games_game_id_seq OWNER TO freecodecamp;

--
-- Name: games_game_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.games_game_id_seq OWNED BY public.games.game_id;


--
-- Name: users; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.users (
    user_id integer NOT NULL,
    username character varying(22)
);


ALTER TABLE public.users OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.users_user_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.users_user_id_seq OWNER TO freecodecamp;

--
-- Name: users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.users_user_id_seq OWNED BY public.users.user_id;


--
-- Name: game_description game_description_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.game_description ALTER COLUMN game_description_id SET DEFAULT nextval('public.game_description_game_description_id_seq'::regclass);


--
-- Name: games game_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games ALTER COLUMN game_id SET DEFAULT nextval('public.games_game_id_seq'::regclass);


--
-- Name: users user_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users ALTER COLUMN user_id SET DEFAULT nextval('public.users_user_id_seq'::regclass);


--
-- Data for Name: game_description; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Data for Name: games; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: freecodecamp
--



--
-- Name: game_description_game_description_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.game_description_game_description_id_seq', 1, false);


--
-- Name: games_game_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.games_game_id_seq', 1, false);


--
-- Name: users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.users_user_id_seq', 1, false);


--
-- Name: game_description game_description_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.game_description
    ADD CONSTRAINT game_description_pkey PRIMARY KEY (game_description_id);


--
-- Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT games_pkey PRIMARY KEY (game_id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);


--
-- Name: game_description game_description_game_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.game_description
    ADD CONSTRAINT game_description_game_id_fkey FOREIGN KEY (game_id) REFERENCES public.games(game_id);


--
-- Name: games games_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.games
    ADD CONSTRAINT games_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(user_id);


--
-- PostgreSQL database dump complete
--


But anyway, thanks a lot for your time @hbar1st. I really appreciate it :slight_smile:

1 Like

Amazing information.