feat: add a project model
This commit is contained in:
parent
2262111f97
commit
283b3965db
2
migrations/2024-08-16-221326_create_projects/down.sql
Normal file
2
migrations/2024-08-16-221326_create_projects/down.sql
Normal file
@ -0,0 +1,2 @@
|
||||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE IF EXISTS "projects";
|
6
migrations/2024-08-16-221326_create_projects/up.sql
Normal file
6
migrations/2024-08-16-221326_create_projects/up.sql
Normal file
@ -0,0 +1,6 @@
|
||||
-- Your SQL goes here
|
||||
CREATE TABLE "projects"(
|
||||
"id" SERIAL NOT NULL PRIMARY KEY,
|
||||
"title" TEXT NOT NULL
|
||||
);
|
||||
|
1
src/models/mod.rs
Normal file
1
src/models/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub(crate) mod project;
|
17
src/models/project.rs
Normal file
17
src/models/project.rs
Normal file
@ -0,0 +1,17 @@
|
||||
use crate::schema::projects;
|
||||
use diesel::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Queryable, Selectable, Serialize, Deserialize)]
|
||||
#[diesel(table_name = crate::schema::projects)]
|
||||
#[diesel(check_for_backend(diesel::pg::Pg))]
|
||||
pub struct Project {
|
||||
pub(crate) id: i32,
|
||||
pub(crate) title: String,
|
||||
}
|
||||
|
||||
#[derive(Insertable, Serialize, Deserialize)]
|
||||
#[diesel(table_name = projects)]
|
||||
pub struct NewProject<'a> {
|
||||
pub title: &'a str,
|
||||
}
|
8
src/schema/mod.rs
Normal file
8
src/schema/mod.rs
Normal file
@ -0,0 +1,8 @@
|
||||
// @generated automatically by Diesel CLI.
|
||||
|
||||
diesel::table! {
|
||||
projects (id) {
|
||||
id -> Int4,
|
||||
title -> Text,
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user