Skip to content

Commit

Permalink
product and rating tables added
Browse files Browse the repository at this point in the history
  • Loading branch information
vsilent committed Sep 3, 2023
1 parent c1f4118 commit 374d906
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
9 changes: 0 additions & 9 deletions migrations/20230604060546_create_user_stack_table.sql

This file was deleted.

8 changes: 8 additions & 0 deletions migrations/20230903063840_creating_rating_tables.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Add down migration script here

DROP INDEX idx_category;
DROP INDEX idx_user_id;
DROP INDEX idx_product_id_rating_id;

DROP table rating;
DROP table product;
28 changes: 28 additions & 0 deletions migrations/20230903063840_creating_rating_tables.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Add up migration script here

CREATE TABLE product (
id integer NOT NULL, PRIMARY KEY(id),
obj_id integer NOT NULL,
obj_type TEXT NOT NULL,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL
);

CREATE TABLE rating (
id integer NOT NULL, PRIMARY KEY(id),
user_id uuid NOT NULL,
product_id integer NOT NULL,
category VARCHAR(255) NOT NULL,
comment TEXT DEFAULT NULL,
hidden BOOLEAN DEFAULT FALSE,
rate INTEGER,
created_at timestamptz NOT NULL,
updated_at timestamptz NOT NULL,
CONSTRAINT fk_product
FOREIGN KEY(product_id)
REFERENCES product(id)
);

CREATE INDEX idx_category ON rating(category);
CREATE INDEX idx_user_id ON rating(user_id);
CREATE INDEX idx_product_id_rating_id ON rating(product_id, rate);
2 changes: 1 addition & 1 deletion src/models/rating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Product {
pub struct Rating {
pub id: i32,
pub user_id: Uuid, // external user_id, 100, taken using token (middleware?)
pub category: String,
pub category: String, // rating of product | rating of service etc
pub comment: String, // always linked to a product
pub hidden: bool, // rating can be hidden for non-adequate user behaviour
pub rate: u32,
Expand Down

0 comments on commit 374d906

Please sign in to comment.