diff --git a/db/migrations/0003_tan_darwin.sql b/db/migrations/0003_tan_darwin.sql new file mode 100644 index 0000000..23d7fd1 --- /dev/null +++ b/db/migrations/0003_tan_darwin.sql @@ -0,0 +1 @@ +ALTER TABLE "users" ALTER COLUMN "bio" SET DEFAULT ''; \ No newline at end of file diff --git a/db/migrations/meta/0003_snapshot.json b/db/migrations/meta/0003_snapshot.json new file mode 100644 index 0000000..1c2ed1f --- /dev/null +++ b/db/migrations/meta/0003_snapshot.json @@ -0,0 +1,143 @@ +{ + "version": "5", + "dialect": "pg", + "id": "a00f4b17-7f1e-4d73-86c5-48cc1aaa92ec", + "prevId": "d3648b42-2fea-42c2-a1d8-e55af14ec90a", + "tables": { + "user_follows": { + "name": "user_follows", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "follower_id": { + "name": "follower_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "date", + "primaryKey": false, + "notNull": false, + "default": "CURRENT_DATE" + }, + "updated_at": { + "name": "updated_at", + "type": "date", + "primaryKey": false, + "notNull": false, + "default": "CURRENT_DATE" + } + }, + "indexes": {}, + "foreignKeys": { + "user_follows_user_id_users_id_fk": { + "name": "user_follows_user_id_users_id_fk", + "tableFrom": "user_follows", + "tableTo": "users", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "user_follows_follower_id_users_id_fk": { + "name": "user_follows_follower_id_users_id_fk", + "tableFrom": "user_follows", + "tableTo": "users", + "columnsFrom": ["follower_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "user_follows_user_id_follower_id": { + "name": "user_follows_user_id_follower_id", + "columns": ["user_id", "follower_id"] + } + }, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bio": { + "name": "bio", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'https://api.realworld.io/images/smiley-cyrus.jpg'" + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "date", + "primaryKey": false, + "notNull": false, + "default": "CURRENT_DATE" + }, + "updated_at": { + "name": "updated_at", + "type": "date", + "primaryKey": false, + "notNull": false, + "default": "CURRENT_DATE" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + } + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} diff --git a/db/migrations/meta/_journal.json b/db/migrations/meta/_journal.json index d56ed13..215fcf2 100644 --- a/db/migrations/meta/_journal.json +++ b/db/migrations/meta/_journal.json @@ -22,6 +22,13 @@ "when": 1696453057809, "tag": "0002_aberrant_the_hunter", "breakpoints": false + }, + { + "idx": 3, + "version": "5", + "when": 1697458638871, + "tag": "0003_tan_darwin", + "breakpoints": false } ] } diff --git a/src/users/users.model.ts b/src/users/users.model.ts index 8133c44..58109ed 100644 --- a/src/users/users.model.ts +++ b/src/users/users.model.ts @@ -11,7 +11,7 @@ import { export const users = pgTable('users', { id: serial('id').primaryKey(), email: text('email').unique().notNull(), - bio: text('bio'), + bio: text('bio').default(''), image: text('image').default( 'https://api.realworld.io/images/smiley-cyrus.jpg', ), diff --git a/src/users/users.schema.ts b/src/users/users.schema.ts index c6de03e..685f782 100644 --- a/src/users/users.schema.ts +++ b/src/users/users.schema.ts @@ -6,7 +6,13 @@ import { users } from './users.model'; // Schema for inserting a user - can be used to validate API requests export const insertUserSchemaRaw = createInsertSchema(users); export const InsertUserSchema = Type.Object({ - user: Type.Omit(insertUserSchemaRaw, ['id', 'created_at', 'updated_at']), + user: Type.Omit(insertUserSchemaRaw, [ + 'id', + 'created_at', + 'updated_at', + 'bio', + 'image', + ]), }); export const UpdateUserSchema = Type.Object({