Seed Data

noun

say it: “SEED DAY-tuh” /sid ˈdeɪtə/

Starting rows an app puts into an empty database, such as demo records, so it has something to show from its first request.

What is seed data?

Seed data is the starting rows an app puts into an empty database, such as six demo trails, so it has something to show from its first request. Seeding only when the table is empty keeps any rows that are already there.

import sqlite3

conn = sqlite3.connect(":memory:")
conn.execute("CREATE TABLE trails (name TEXT, status TEXT)")

def seed(conn):
    if conn.execute("SELECT COUNT(*) FROM trails").fetchone()[0] == 0:   # only an empty table
        conn.executemany("INSERT INTO trails VALUES (?, ?)", [("Cedar Loop", "open"), ("Ridge Run", "muddy")])

seed(conn)
seed(conn)   # the next start finds rows there and adds none
print(conn.execute("SELECT COUNT(*) FROM trails").fetchone()[0])   # 2

In a sentence

  • “The API adds seed data only when the table is empty, so rows already there stay.”
  • “Each start on the free host adds the six demo trails as seed data, because the disk was wiped.”

Level: Apprentice · More Database terms at this level

Updated