Column types and identifier quoting differ enough between dialects that a script written for Postgres will not run on MySQL. Pick a dialect here and both the types and the quoting come out right, so the script runs as pasted.
What you can control
- Four dialects with correct type mapping —
TIMESTAMPTZin Postgres becomesDATETIMEin MySQL andTEXTin SQLite. - Identifier quoting follows each dialect: double quotes, backticks or square brackets.
- One multi-row INSERT for speed, or one statement per row when you need them individually.
- Optional transaction wrapping and a truncate statement for repeatable re-seeding.
What this is not
The generated CREATE TABLE has no indexes, foreign keys or constraints beyond a primary key. It is a seed script, not a schema migration.
Questions
Does the CREATE TABLE include indexes?
No, just columns and a primary key on id when that field is present. Add indexes and constraints in your own migration.
Are string values escaped safely?
Single quotes are doubled, which is the standard SQL escape. The values themselves are generated rather than user-supplied, so there is nothing hostile in them.
Why is one multi-row INSERT faster?
Because it is one statement and one round trip instead of hundreds. For thousands of rows the difference is substantial.