Skip to content

Commit

Permalink
MySQL schema added
Browse files Browse the repository at this point in the history
  • Loading branch information
schu96 committed Feb 16, 2023
1 parent c3d5a1b commit bfeda4f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const reviewchars = new Schema({
value: Number,
});

const ReviewChars = mongoose.model('reviewchars', reviewchars);
const ReviewChars = mongoose.model('ReviewChars', reviewchars);

const save = (id, char_id, review_id, value) => {
const newEntry = new ReviewChars();
Expand All @@ -35,7 +35,7 @@ const reviewphotos = new Schema({
url: String,
});

const ReviewPhotos = mongoose.model('reviewphotos', reviewphotos);
const ReviewPhotos = mongoose.model('ReviewPhotos', reviewphotos);

const savePhotos = (id, review_id, url) => {
const photoEntry = new ReviewPhotos();
Expand Down
3 changes: 2 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { dat } = require('../jsonConvert.js');

const app = express();

// app.use(express.json());
app.use(express.json());
// fs.createReadStream(path.join(__dirname, '../sourceFiles/characteristic_reviews.csv'))
// .pipe(csvParser())
// .pipe(through2({ objectMode: true }, (row, enc, cb) => {
Expand Down Expand Up @@ -38,5 +38,6 @@ const app = express();
}
}, {$out:"ReviewChars"}], {allowDiskUse:true})
*/

app.listen(process.env.PORT);
console.log(`Listening at http://localhost:${process.env.PORT}`);
34 changes: 34 additions & 0 deletions server/reviewSchema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE DATABASE IF NOT EXISTS Reviews;
USE Reviews;

CREATE TABLE IF NOT EXISTS reviews(
id INT NOT NULL,
product_id INT NOT NULL,
rating INT,
summary TEXT,
body TEXT,
recommend BOOLEAN,
reported BOOLEAN,
name TEXT,
email TEXT,
PRIMARY KEY(id),
FOREIGN KEY (photos) REFERENCES reviewPhotos(review_id),
FOREIGN KEY (characteristics) REFERENCES reviewCharacteristics(review_id)
)
CREATE TABLE IF NOT EXISTS reviewPhotos(
review_id INT NOT NULL,
url TEXT
)
CREATE TABLE IF NOT EXISTS meta (
product_id INT NOT NULL,
ratings TEXT,
recommend TEXT,
PRIMARY KEY (product_id),
FOREIGN KEY (characteristics) REFERENCES reviewCharacteristics(review_id)
)
CREATE TABLE IF NOT EXISTS reviewCharacteristics (
review_id INT NOT NULL,
characteristic_id INT,
recommend INT,
value INT,
)

0 comments on commit bfeda4f

Please sign in to comment.