mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-25 07:49:37 +02:00
Update database schema and add signup_date, last_login, and role columns to user table
This commit is contained in:
parent
f0eb5441f0
commit
2249052ab7
10 changed files with 456 additions and 2 deletions
|
@ -7,6 +7,8 @@ services:
|
|||
- DATABASE_URL=postgres://adventurelog:PO24VjITwGgk@db:5432/adventurelog
|
||||
# ORIGIN is only necessary when not using a reverse proxy or hosting that includes https
|
||||
- ORIGIN=http://localhost:3000
|
||||
- SKIP_DB_WAIT=false
|
||||
# Only necessary for externaly hosted databases such as NeonDB
|
||||
depends_on:
|
||||
- db
|
||||
volumes:
|
||||
|
|
3
migrations/0003_easy_iron_monger.sql
Normal file
3
migrations/0003_easy_iron_monger.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE "user" ADD COLUMN "signup_date" timestamp with time zone NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "user" ADD COLUMN "last_login" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "user" ADD COLUMN "role" text NOT NULL;
|
409
migrations/meta/0003_snapshot.json
Normal file
409
migrations/meta/0003_snapshot.json
Normal file
|
@ -0,0 +1,409 @@
|
|||
{
|
||||
"id": "72cc9a9a-a12e-4ca2-b644-b704673af4d7",
|
||||
"prevId": "91692e84-91ec-4411-ad9d-7b8b14f67dda",
|
||||
"version": "5",
|
||||
"dialect": "pg",
|
||||
"tables": {
|
||||
"featuredAdventures": {
|
||||
"name": "featuredAdventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"location": {
|
||||
"name": "location",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"featuredAdventures_name_unique": {
|
||||
"name": "featuredAdventures_name_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"session": {
|
||||
"name": "session",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"expires_at": {
|
||||
"name": "expires_at",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"session_user_id_user_id_fk": {
|
||||
"name": "session_user_id_user_id_fk",
|
||||
"tableFrom": "session",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"sharedAdventures": {
|
||||
"name": "sharedAdventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"data": {
|
||||
"name": "data",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"date": {
|
||||
"name": "date",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"user": {
|
||||
"name": "user",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "text",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"first_name": {
|
||||
"name": "first_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"last_name": {
|
||||
"name": "last_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"icon": {
|
||||
"name": "icon",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"hashed_password": {
|
||||
"name": "hashed_password",
|
||||
"type": "varchar",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"signup_date": {
|
||||
"name": "signup_date",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"last_login": {
|
||||
"name": "last_login",
|
||||
"type": "timestamp with time zone",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"role": {
|
||||
"name": "role",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"userVisitedAdventures": {
|
||||
"name": "userVisitedAdventures",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"adventure_id": {
|
||||
"name": "adventure_id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"adventure_name": {
|
||||
"name": "adventure_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"location": {
|
||||
"name": "location",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"visited_date": {
|
||||
"name": "visited_date",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"userVisitedAdventures_user_id_user_id_fk": {
|
||||
"name": "userVisitedAdventures_user_id_user_id_fk",
|
||||
"tableFrom": "userVisitedAdventures",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"userVisitedWorldTravel": {
|
||||
"name": "userVisitedWorldTravel",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"region_id": {
|
||||
"name": "region_id",
|
||||
"type": "varchar",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk": {
|
||||
"name": "userVisitedWorldTravel_country_code_worldTravelCountries_country_code_fk",
|
||||
"tableFrom": "userVisitedWorldTravel",
|
||||
"tableTo": "worldTravelCountries",
|
||||
"columnsFrom": [
|
||||
"country_code"
|
||||
],
|
||||
"columnsTo": [
|
||||
"country_code"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"userVisitedWorldTravel_user_id_user_id_fk": {
|
||||
"name": "userVisitedWorldTravel_user_id_user_id_fk",
|
||||
"tableFrom": "userVisitedWorldTravel",
|
||||
"tableTo": "user",
|
||||
"columnsFrom": [
|
||||
"user_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
},
|
||||
"userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk": {
|
||||
"name": "userVisitedWorldTravel_region_id_worldTravelCountryRegions_id_fk",
|
||||
"tableFrom": "userVisitedWorldTravel",
|
||||
"tableTo": "worldTravelCountryRegions",
|
||||
"columnsFrom": [
|
||||
"region_id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
},
|
||||
"worldTravelCountries": {
|
||||
"name": "worldTravelCountries",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"continent": {
|
||||
"name": "continent",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {
|
||||
"worldTravelCountries_country_code_unique": {
|
||||
"name": "worldTravelCountries_country_code_unique",
|
||||
"nullsNotDistinct": false,
|
||||
"columns": [
|
||||
"country_code"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"worldTravelCountryRegions": {
|
||||
"name": "worldTravelCountryRegions",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "varchar",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"name": {
|
||||
"name": "name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"country_code": {
|
||||
"name": "country_code",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"info": {
|
||||
"name": "info",
|
||||
"type": "json",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk": {
|
||||
"name": "worldTravelCountryRegions_country_code_worldTravelCountries_country_code_fk",
|
||||
"tableFrom": "worldTravelCountryRegions",
|
||||
"tableTo": "worldTravelCountries",
|
||||
"columnsFrom": [
|
||||
"country_code"
|
||||
],
|
||||
"columnsTo": [
|
||||
"country_code"
|
||||
],
|
||||
"onDelete": "no action",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {}
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
}
|
||||
}
|
|
@ -22,6 +22,13 @@
|
|||
"when": 1713125110816,
|
||||
"tag": "0002_far_mephistopheles",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "5",
|
||||
"when": 1713402092365,
|
||||
"tag": "0003_easy_iron_monger",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
|
@ -28,6 +28,15 @@ export const userTable = pgTable("user", {
|
|||
last_name: text("last_name").notNull(),
|
||||
icon: text("icon"),
|
||||
hashed_password: varchar("hashed_password").notNull(),
|
||||
signup_date: timestamp("signup_date", {
|
||||
withTimezone: true,
|
||||
mode: "date",
|
||||
}).notNull(),
|
||||
last_login: timestamp("last_login", {
|
||||
withTimezone: true,
|
||||
mode: "date",
|
||||
}),
|
||||
role: text("role").notNull(),
|
||||
});
|
||||
|
||||
// export type SelectUser = typeof userTable.$inferSelect;
|
||||
|
|
|
@ -20,6 +20,9 @@ export const lucia = new Lucia(adapter, {
|
|||
first_name: attributes.first_name,
|
||||
last_name: attributes.last_name,
|
||||
icon: attributes.icon,
|
||||
signup_date: attributes.signup_date,
|
||||
last_login: attributes.last_login,
|
||||
role: attributes.role,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
@ -38,4 +41,7 @@ export interface DatabaseUser {
|
|||
last_name: string;
|
||||
icon: string;
|
||||
hashed_password: string;
|
||||
signup_date: Date;
|
||||
last_login: Date;
|
||||
role: string;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ export const actions: Actions = {
|
|||
});
|
||||
}
|
||||
|
||||
const existingUser = await db
|
||||
const existingUser:any = await db
|
||||
.select()
|
||||
.from(userTable)
|
||||
.where(eq(userTable.username, username))
|
||||
|
@ -70,6 +70,14 @@ export const actions: Actions = {
|
|||
});
|
||||
}
|
||||
|
||||
await db
|
||||
.update(userTable)
|
||||
.set({
|
||||
last_login: new Date(),
|
||||
})
|
||||
.where(eq(userTable.id, existingUser.id))
|
||||
.execute();
|
||||
|
||||
const session = await lucia.createSession(existingUser.id, {});
|
||||
const sessionCookie = lucia.createSessionCookie(session.id);
|
||||
event.cookies.set(sessionCookie.name, sessionCookie.value, {
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
let last_name = data.user?.last_name;
|
||||
let user_id = data.user?.id;
|
||||
let icon = data.user?.icon;
|
||||
let signup_date = data.user?.signup_date;
|
||||
let role = data.user?.role;
|
||||
</script>
|
||||
|
||||
<h1 class="text-center font-extrabold text-4xl mb-6">Settings Page</h1>
|
||||
|
@ -65,4 +67,6 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<small class="text-center">For Debug Use: UUID={user_id}</small>
|
||||
<small class="text-center"
|
||||
><b>For Debug Use:</b> UUID={user_id} Signup Date={signup_date} Role={role}</small
|
||||
>
|
||||
|
|
|
@ -90,6 +90,9 @@ export const actions: Actions = {
|
|||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
hashed_password: hashedPassword,
|
||||
signup_date: new Date(),
|
||||
role: "user",
|
||||
last_login: new Date(),
|
||||
} as DatabaseUser)
|
||||
.execute();
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ run_sql_scripts() {
|
|||
echo "Starting AdventureLog"
|
||||
|
||||
# Wait for the database to start up
|
||||
if (!$SKIP_DB_WAIT); then
|
||||
wait_for_db
|
||||
fi
|
||||
wait_for_db
|
||||
|
||||
# generate the schema
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue