def gradedb_init(db_connection):
    """Create a new SQLite database for storing grades.
       Creates a database with tables:
         students (id, first_name, last_name, sid, email)
         courses (id, name, number, year, semester)
         course_memberships (id, student_id, course_id)
         assignments (id, course_id, name, description, due_date, grade_type, points, weight)
         grades (id, assignment_id, student_id, value, timestamp)
       db_connection should be a sqlite database connection.
    """
    db_connection.executescript(
        """
    CREATE TABLE students (
      id INTEGER PRIMARY KEY,
      first_name TEXT,
      last_name TEXT,
      sid TEXT UNIQUE,
      email TEXT
    );
    CREATE TABLE courses (
      id INTEGER PRIMARY KEY,
      name TEXT,
      number TEXT,
      year INTEGER,
      semester TEXT
    );
    CREATE TABLE course_memberships (
      id INTEGER PRIMARY KEY,
      student_id INTEGER NOT NULL,
      course_id INTEGER NOT NULL,
      FOREIGN KEY(student_id) REFERENCES students(id),
      FOREIGN KEY(course_id) REFERENCES courses(id),
      UNIQUE(student_id, course_id) ON CONFLICT IGNORE
    );
    CREATE TABLE assignments (
      id INTEGER PRIMARY KEY,
      course_id INTEGER NOT NULL,
      name TEXT,
      description TEXT,
      due_date TEXT,
      grade_type TEXT,
      weight NUMERIC,
      FOREIGN KEY(course_id) REFERENCES courses(id)
    );
    CREATE TABLE grades (
      id INTEGER PRIMARY KEY,
      assignment_id INTEGER NOT NULL,
      student_id INTEGER NOT NULL,
      -- rely on SQLite's dynamic types to store letter grades as text:
      value NUMERIC,
      timestamp TEXT,
      FOREIGN KEY(assignment_id) REFERENCES assignments(id),
      FOREIGN KEY(student_id) REFERENCES students(id)
    );
    """
        )
    return db_connection.commit()
