Skip to content

Commit

Permalink
fix schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fractal-Tess committed May 23, 2024
1 parent 50f3f15 commit 3511996
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 25 deletions.
15 changes: 15 additions & 0 deletions drizzle/0002_quiet_revanche.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ALTER TABLE `namespace` RENAME COLUMN `topicid` TO `topicId`;--> statement-breakpoint
ALTER TABLE `namespace` DROP FOREIGN KEY `namespace_topicid_topic_id_fk`;
--> statement-breakpoint
ALTER TABLE `flashcard` MODIFY COLUMN `id` int AUTO_INCREMENT NOT NULL;--> statement-breakpoint
ALTER TABLE `flashcard` MODIFY COLUMN `question` text NOT NULL;--> statement-breakpoint
ALTER TABLE `flashcard` MODIFY COLUMN `fillerAnswer` text NOT NULL;--> statement-breakpoint
ALTER TABLE `namespace` MODIFY COLUMN `id` int AUTO_INCREMENT NOT NULL;--> statement-breakpoint
ALTER TABLE `namespace` MODIFY COLUMN `label` varchar(64) NOT NULL;--> statement-breakpoint
ALTER TABLE `topic` MODIFY COLUMN `id` int AUTO_INCREMENT NOT NULL;--> statement-breakpoint
ALTER TABLE `topic` MODIFY COLUMN `label` varchar(64) NOT NULL;--> statement-breakpoint
ALTER TABLE `user` MODIFY COLUMN `id` int AUTO_INCREMENT NOT NULL;--> statement-breakpoint
ALTER TABLE `user` MODIFY COLUMN `username` varchar(64) NOT NULL;--> statement-breakpoint
ALTER TABLE `user` MODIFY COLUMN `email` varchar(320) NOT NULL;--> statement-breakpoint
ALTER TABLE `user` MODIFY COLUMN `passwordHash` varchar(255) NOT NULL;--> statement-breakpoint
ALTER TABLE `namespace` ADD CONSTRAINT `namespace_topicId_topic_id_fk` FOREIGN KEY (`topicId`) REFERENCES `topic`(`id`) ON DELETE no action ON UPDATE no action;
191 changes: 191 additions & 0 deletions drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
{
"version": "5",
"dialect": "mysql",
"id": "f39ecb2f-e883-43ca-b43a-987a9f0e37bc",
"prevId": "f7a34dae-8504-4c15-8748-b3c1fe98ddd0",
"tables": {
"flashcard": {
"name": "flashcard",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"question": {
"name": "question",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"correctAnswer": {
"name": "correctAnswer",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"fillerAnswer": {
"name": "fillerAnswer",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"flashcard_id": {
"name": "flashcard_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {}
},
"namespace": {
"name": "namespace",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"public": {
"name": "public",
"type": "boolean",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"label": {
"name": "label",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"topicId": {
"name": "topicId",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"namespace_topicId_topic_id_fk": {
"name": "namespace_topicId_topic_id_fk",
"tableFrom": "namespace",
"tableTo": "topic",
"columnsFrom": [
"topicId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"namespace_id": {
"name": "namespace_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {}
},
"topic": {
"name": "topic",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"label": {
"name": "label",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"topic_id": {
"name": "topic_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {}
},
"user": {
"name": "user",
"columns": {
"id": {
"name": "id",
"type": "int",
"primaryKey": false,
"notNull": true,
"autoincrement": true
},
"username": {
"name": "username",
"type": "varchar(64)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "varchar(320)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"passwordHash": {
"name": "passwordHash",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {
"user_id": {
"name": "user_id",
"columns": [
"id"
]
}
},
"uniqueConstraints": {}
}
},
"_meta": {
"schemas": {},
"tables": {},
"columns": {
"\"namespace\".\"topicid\"": "\"namespace\".\"topicId\""
}
}
}
9 changes: 8 additions & 1 deletion drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1716230100142,
"tag": "0001_supreme_valeria_richards",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 1716428069013,
"tag": "0002_quiet_revanche",
"breakpoints": true
}
]
}
}
39 changes: 26 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
"@faker-js/faker": "^8.4.1",
"@t3-oss/env-nextjs": "^0.10.1",
"argon2": "^0.40.1",
"drizzle-orm": "^0.29.4",
"mysql2": "^3.9.7",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"drizzle-kit": "^0.21.2",
"drizzle-kit": "^0.21.4",
"drizzle-orm": "^0.30.10",
"eslint": "^8",
"eslint-config-next": "14.2.3",
"postcss": "^8",
"prettier": "^3.2.5",
"prettier-plugin-tailwindcss": "^0.5.14",
"react": "^18.3.1",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
Expand Down
6 changes: 3 additions & 3 deletions src/db/schema/flashcard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { int, mysqlTable, text } from 'drizzle-orm/mysql-core';

export const flashcard = mysqlTable('flashcard', {
id: int('id').primaryKey(),
question: text('question'),
id: int('id').primaryKey().autoincrement(),
question: text('question').notNull(),
correctAnswer: text('correctAnswer'),
// TODO: convert to typed json
fillerAnswer: text('fillerAnswer'),
fillerAnswer: text('fillerAnswer').notNull(),
});
Loading

0 comments on commit 3511996

Please sign in to comment.