반응형
아.. 오늘 병원이랑 레슨 있었는데 어제 밤 새버렸고 너무 가기 싫어서 다 안 가버림..
내일~월요일에 가야겠다
낮잠 잔다고 하루 날린 것 같아서 기부니가 좋지 않음
역시 밤 새면 안 된다 !!!!!!
오랜만에 다시 새기고 갑니다 .....
🚀 요약
작업 시간: 3시간
✅ DB설계 및 ERD 작성
✅ PostgreSQL로 DB 구축
✅ .NET 애플리케이션에서 Npgsql 라이브러리 연결
🚀 ERD 작성
https://dbdiagram.io/d 툴을 이용해 ERD를 작성해 보았다.
dbdiagram.io - Database Relationship Diagrams Design Tool
dbdiagram.io
오늘 작성한 ERD
이.이정도면.. 됏겟지 ..?...........
Table users {
id UUID [primary key]
profile_image_url TEXT
username VARCHAR(50) [unique, not null]
birthday DATE
email VARCHAR(100) [unique]
password_hash TEXT [not null]
created_at TIMESTAMP [not null, default: "now"]
updated_at TIMESTAMP
}
Table events {
id UUID [primary key]
user_id UUID [not null, ref: > users.id]
category_id UUID [ref: > categories.id]
title VARCHAR(255) [not null]
description TEXT
created_at TIMESTAMP [not null, default: "now"]
updated_at TIMESTAMP
}
Table event_participants {
id UUID [primary key]
event_id UUID [ref: > events.id]
user_id UUID [ref: > users.id]
created_at TIMESTAMP [default: "now"]
}
Table categories {
id UUID [primary key]
category_name VARCHAR(50) [unique, not null]
}
Table event_images {
id UUID [primary key]
event_id UUID
image_url TEXT [not null]
}
Table comments {
id UUID [primary key]
event_id UUID [ref: > events.id]
user_id UUID [ref: > users.id, not null]
parent_comment_id UUID [ref: > comments.id, default: null]
content TEXT [not null]
created_at TIMESTAMP [default: "now", not null]
updated_at TIMESTAMP
}
Table likes {
id UUID [primary key]
user_id UUID [not null]
event_id UUID
comment_id UUID
}
Table notifications {
id UUID [primary key]
recieve_user_id UUID [not null, ref: > users.id] // 알림을 받은 사용자
act_user_id UUID [not null, ref: > users.id]
type VARCHAR(50) [not null] // 알림 종류 (예: "댓글", "좋아요")
read BOOLEAN [default: false] // 읽었는지 여부
created_at TIMESTAMP [default: "now"] // 알림 생성 시간
}
Ref: event_images.event_id > events.id
Ref: likes.event_id > events.id
Ref: likes.comment_id > comments.id
Ref: likes.user_id > users.id
🚀 PostgreSQL로 DB 구축
GUI는 지피티가 추천해준 TablePlus 설치하였읍니다.
간단하게 테이블 만들고 더미 데이터 넣어줌.
🚀 .NET 애플리케이션에서 Npgsql 라이브러리 연결
Npgsql 라이브러리 설치
dotnet add package Npgsql
C# 코드 작성
using System;
using Npgsql;
class Program
{
static void Main()
{
// 연결 문자열
string connString = "Host=localhost;Port=5432;Username=postgres;Password=yourpassword;Database=yourdatabase";
using (var conn = new NpgsqlConnection(connString))
{
conn.Open();
// 간단한 쿼리 실행
using (var cmd = new NpgsqlCommand("SELECT version()", conn))
{
var version = cmd.ExecuteScalar().ToString();
Console.WriteLine($"PostgreSQL version: {version}");
}
}
}
}
DB 연결해서 더미 데이터 가져오기 완!
오늘 작업을 많이 해서 내일부터 백엔드 구조 설계하면 될 것 같다.!!!!
반응형
'study > 100 days (100일 챌린지)' 카테고리의 다른 글
[웹개발 100일] Day 11 - 모델 파일 생성, 마이그레이션 실행해보기 (실패!) (5) | 2025.02.24 |
---|---|
[웹개발 100일] Day 10 - ASP.NET Core + PostgreSQL 프로젝트 생성, DB 마이그레이션, API 엔드포인트 테스트 (7) | 2025.02.23 |
[웹개발 100일] Day 8 - 화면 기획 (figma 활용) (8) | 2025.02.21 |
[웹개발 100일] Day 7 - 화면 기획 (figma 활용) (9) | 2025.02.20 |
[웹개발 100일] Day 6 - 반성문, 새로운 주차별 계획 (8) | 2025.02.19 |