prisma init
π¨βπΌ Great job making the schema. We're a little ways away from actually being
able to use this in our application since we've got more models we need to
create, but this is a good start.
π¦ If you would like to check out the SQL that's generated by the prisma schema
and you don't want to wait until we get to the
npx prisma migrate
exercise,
you can ask SQLite to output a SQL file that represents the contents of the
database (including tables).First, you
will need to
download and install the
sqlite3
CLI.I personally use Homebrew for doing this on macOS. If
you're on Windows, please make a suggestion here for how to do this!
For Linux users:
sh nonumber sudo apt update sudo apt install sqlite3 sqlite3 -version
Once you have that installed, then you can run
sqlite3
from the command line:sqlite3 prisma/data.db .dump > data.sql
Then you can check
data.sql
and it should show you something like this:PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "User" (
"id" TEXT NOT NULL PRIMARY KEY,
"email" TEXT NOT NULL,
"username" TEXT NOT NULL,
"name" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO User VALUES('clklmcxa50000x7drb1zc5bbu','kody@kcd.dev','kody','Kody',1690490436990,1690490427769);
CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
COMMIT;
Cool, huh? You can do that at any time if you're interested to check out how you
could represent the current state of the database as SQL commands.