codu-code / codu

Codú's open-source codebase. A space for coders. Visit our community!
https://codu.co/
Apache License 2.0
121 stars 101 forks source link

Setting up environment: Issue with running the "db:push": "drizzle-kit push" script #1043

Open chvainickas opened 1 day ago

chvainickas commented 1 day ago

Context

Trying to populate to populate the DB with dummy data.

Expected Behavior

After running both the "db:push": "drizzle-kit push" and "db:seed": "npx tsx -r dotenv/config ./drizzle/seed.ts" the DB should populate the Articles and Events with dummy data

Current Behavior

Error in after running the first db:push command. Please see log below.

npm run db:push       

> codu@0.1.0 db:push
> drizzle-kit push

drizzle-kit: v0.22.8
drizzle-orm: v0.31.2

No config path provided, using default path
Reading config file '/home/ed/workspace/codu/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...
· You're about to add Tag_id_unique unique constraint to the table, which contains 10 items. If this statement fails, you will receive an error from the database. Do you want to truncate Tag table?

 Warning  You are about to execute current statements:

ALTER TABLE "Community" ALTER COLUMN "excerpt" SET DEFAULT '';
ALTER TABLE "Post" ALTER COLUMN "excerpt" SET DEFAULT '';
ALTER TABLE "user" ALTER COLUMN "bio" SET DEFAULT '';
ALTER TABLE "BannedUsers" ADD CONSTRAINT "BannedUsers_id_unique" UNIQUE("id");
ALTER TABLE "Bookmark" ADD CONSTRAINT "Bookmark_id_unique" UNIQUE("id");
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_id_unique" UNIQUE("id");
ALTER TABLE "Community" ADD CONSTRAINT "Community_id_unique" UNIQUE("id");
ALTER TABLE "Flagged" ADD CONSTRAINT "Flagged_id_unique" UNIQUE("id");
ALTER TABLE "Like" ADD CONSTRAINT "Like_id_unique" UNIQUE("id");
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_id_unique" UNIQUE("id");
ALTER TABLE "Event" ADD CONSTRAINT "Event_id_unique" UNIQUE("id");
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_id_unique" UNIQUE("id");

error: relation "BannedUsers_id_unique" already exists
    at /home/ed/workspace/codu/node_modules/drizzle-kit/bin.cjs:77696:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.query (/home/ed/workspace/codu/node_modules/drizzle-kit/bin.cjs:119635:26)
    at async pgPush (/home/ed/workspace/codu/node_modules/drizzle-kit/bin.cjs:122560:13)
    at async _Command.<anonymous> (/home/ed/workspace/codu/node_modules/drizzle-kit/bin.cjs:129681:7) {
  length: 103,
  severity: 'ERROR',
  code: '42P07',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'index.c',
  line: '873',
  routine: 'index_create'
}

Screenshots

Drag and drop screenshots here to better describe your issue

Steps to reproduce

Please provide detailed steps for reproducing the issue

Please follow the steps in README to step 6.

Additional info

It is the same issue with docker running

chvainickas commented 1 day ago

Also should mention I am using Ubuntu 24.04

John-Paul-Larkin commented 1 day ago

Awesome, thanks for this Edward. I didn't run into this when seeding the db, so its good that you flagged this issue.

JohnAllenTech commented 13 hours ago

Have you tried the db:nuke script?

npm run db:nuke I think it is?

This will wipe your DB. Then try

npm run db:push

John-Paul-Larkin commented 11 hours ago

Great name for that command 🤣 @chvainickas You should listen to John, he actually knows what he talking about 🚀

chvainickas commented 3 hours ago

` ~/workspace/codu develop !3  anaconda3

npm run db:nuke

codu@0.1.0 db:nuke npx tsx -r dotenv/config ./drizzle/nuke.ts

This will delete all data. Are you sure? (y/n) y { severity_local: 'NOTICE', severity: 'NOTICE', code: '00000', message: 'drop cascades to 18 other objects', detail: 'drop cascades to type "Role"\n' + 'drop cascades to table account\n' + 'drop cascades to table "BannedUsers"\n' + 'drop cascades to table "Bookmark"\n' + 'drop cascades to table "Comment"\n' + 'drop cascades to table "Community"\n' + 'drop cascades to table "Event"\n' + 'drop cascades to table "Flagged"\n' + 'drop cascades to table "Like"\n' + 'drop cascades to table "Membership"\n' + 'drop cascades to table "Notification"\n' + 'drop cascades to table "Post"\n' + 'drop cascades to table "PostTag"\n' + 'drop cascades to table "RSVP"\n' + 'drop cascades to table session\n' + 'drop cascades to table "Tag"\n' + 'drop cascades to table "user"\n' + 'drop cascades to table "verificationToken"', file: 'dependency.c', line: '1213', routine: 'reportDependentObjects' } node:internal/process/promises:288 triggerUncaughtException(err, true / fromPromise /); ^

PostgresError: schema "drizzle" does not exist at ErrorResponse (/home/ed/workspace/codu/node_modules/postgres/cjs/src/connection.js:788:26) at handle (/home/ed/workspace/codu/node_modules/postgres/cjs/src/connection.js:474:6) at Socket.data (/home/ed/workspace/codu/node_modules/postgres/cjs/src/connection.js:315:9) at Socket.emit (node:events:517:28) at addChunk (node:internal/streams/readable:368:12) at readableAddChunk (node:internal/streams/readable:341:9) at Readable.push (node:internal/streams/readable:278:10) at TCP.onStreamRead (node:internal/stream_base_commons:190:23) { severity_local: 'ERROR', severity: 'ERROR', code: '3F000', file: 'namespace.c', line: '3096', routine: 'get_namespace_oid' }

Node.js v18.19.1 `

chvainickas commented 3 hours ago

I have ran the DB:nuke and I guess something is not working

John-Paul-Larkin commented 3 hours ago

The joys of development Edward. 🤣 Maybe try deleting the docker container and creating a new instance?