# Study Party API

Do not lose migrations/\_current.json!
It is used to create migrations for changes since previous database state

# Create Migration

node node_modules\sequelize-auto-migrations-v2\bin\makemigration.js --name migrationName

# Development

## Run Tests

Tests are written in Jest originally by GitHub Copilot
npm run test

## Create MySql database

CREATE DATABASE database_development CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

## Run Migrations

npx sequelize-cli db:migrate --env development

## Run Seeders

npx sequelize-cli db:seed:all --env development

## Undo Most Recent Seeder

npx sequelize-cli db:seed:undo --env development

## Make an existing user sa

npm run make-sa-dev

## Make an existing user admin

npm run make-admin-dev

## Add student user - Only one per school

npm run add-student-dev

## Bootstrap development env database

1. Run create database
2. Run Migrations
3. Run seeders
4. Add sa user

## SQL to copy questions stuff to terms after running fixTerms migration

INSERT INTO terms (`id`, `text`, `updatedAt`, `topicId`) SELECT `id`, `text`, `updatedAt`, `topicId` FROM questions;
INSERT INTO termsData (`id`, `resources`, `termId`) SELECT `id`, `resources`, `questionId` FROM questionsData;
INSERT INTO definitions (`id`, `text`, `termId`) SELECT `id`, `text`, `questionId` FROM answers;

## SQL to delete from questions tables and reset auto increment after running fixTerms migration

DELETE FROM questions;
DELETE FROM questionsData;
DELETE FROM answers;

ALTER TABLE questions AUTO_INCREMENT = 1;
ALTER TABLE questionsData AUTO_INCREMENT = 1;
ALTER TABLE answers AUTO_INCREMENT = 1;

---

# Production

## Create MySql database

CREATE DATABASE monocool_study_party CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

## Run Migrations

npx sequelize-cli db:migrate --env production

## Run Seeders

npx sequelize-cli db:seed:all --env production

## Undo Most Recent Seeder

npx sequelize-cli db:seed:undo --env production

## Make an existing user admin

npm run make-admin-prod

## Make an existing user sa

npm run make-sa-prod

## Add student user - Only one per school

npm run add-student-prod
