CarePet is a web application that allows users to monitor their pets' health and well-being. It is a full-stack application that uses NestJS for the backend, Svelte for the frontend, and ScyllaDB for the database.
Your task is to set up the database and implement the queries that the backend needs to perform to work properly. You will be given a Docker Compose file that will start the backend, frontend, and database for you.
- Docker
- Docker Compose
- Node.js >= 16.0.0
- NPM
- CQL Shell
$ git clone https://github.com/CustomEntity/workshop-scylladb.git
$ cd workshop-scylladb
$ cd backend
$ npm install
$ cd ..
$ cd frontend
$ npm install
Run the following command to start the database:
$ docker-compose up
Run the following command to start the backend:
$ cd backend
$ npm run start
Run the following command to start the frontend:
$ cd frontend
$ npm run dev
After starting the Docker Compose file, you should be able to connect to the database using the CQL shell.
The keyspace is the top-level container for all data in ScyllaDB. It is similar to a database in other databases.
You have to create a keyspace called carepet
with a replication factor of 1 and a simple strategy.
You have to create the following tables:
owner
, pet
, sensor
, measurement
.
For the measurement
table, you have have to use TimeWindowCompactionStrategy compaction strategy.
We will use the following schema:
owner
table:
Column name | Type |
---|---|
owner_id | UUID |
address | text |
name | text |
PRIMARY KEY | owner_id |
pet
table:
Column name | Type |
---|---|
owner_id | UUID |
pet_id | UUID |
chip_id | text |
species | text |
breed | text |
color | text |
gender | text |
age | int |
weight | float |
address | text |
name | text |
PRIMARY KEY | (owner_id, pet_id) |
sensor
table:
Column name | Type |
---|---|
pet_id | UUID |
sensor_id | UUID |
PRIMARY KEY | (pet_id, sensor_id) |
measurement
table:
Column name | Type |
---|---|
sensor_id | UUID |
ts | timestamp |
value | float |
PRIMARY KEY | (sensor_id, ts) |
Compaction | TimeWindowCompactionStrategy |
You have to populate the database using the npm run populate
command in the backend
directory.
You have to implement the queries in the backend/src/sensor/sensor.service.ts
, backend/src/pet/pet.service.ts
and backend/src/owner/owner.service.ts
files.