Skip to content

Commit

Permalink
fix: remove bio and image fields from insert
Browse files Browse the repository at this point in the history
  • Loading branch information
yamcodes committed Oct 16, 2023
1 parent 98510ed commit d4b9d8a
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 2 deletions.
1 change: 1 addition & 0 deletions db/migrations/0003_tan_darwin.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "users" ALTER COLUMN "bio" SET DEFAULT '';
143 changes: 143 additions & 0 deletions db/migrations/meta/0003_snapshot.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
}
7 changes: 7 additions & 0 deletions db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
2 changes: 1 addition & 1 deletion src/users/users.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
Expand Down
8 changes: 7 additions & 1 deletion src/users/users.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit d4b9d8a

Please sign in to comment.