Skip to content

Commit

Permalink
Adding Basic Database Seeding (#73)
Browse files Browse the repository at this point in the history
* Added Migration

* Work on seeding DB

* I think team/event linking working

* Finished seeding function for teams/events

* Applied linting

* fix prisma datatype

* Event improvement

* Added basic utils page to trigger Seeding

* Added prisma migrate github action

* Testing

* Formatting

* Fixed lodash types

---------

Co-authored-by: Adam Garcia <[email protected]>
Co-authored-by: warren yun <[email protected]>
  • Loading branch information
3 people authored May 25, 2023
1 parent 0b5e625 commit d8a9f9e
Show file tree
Hide file tree
Showing 16 changed files with 604 additions and 63 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/prismaMigrate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Prisma Migrate
# https://blog.henriktech.com/deploying-prisma-migrations-via-github-actions

on:
push:
branches: [staging]
paths:
- "./prisma/**/*.*"
pull_request:

jobs:
install:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup Nodejs
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: "yarn"

- name: Install
run: yarn install
- name: Rerun Install
run: yarn install

generate:
runs-on: ubuntu-latest

needs: install

steps:
- uses: actions/checkout@v2

- name: Setup Nodejs
uses: actions/setup-node@v2
with:
node-version: 16.x
cache: "yarn"

- name: Install
run: yarn install

- run: rm -rf node_modules/.prisma

- name: Generate Prisma Client
run: npx prisma generate

# migrate:
# runs-on: ubuntu-latest

# needs: install

# steps:
# - uses: actions/checkout@v2

# - name: Setup Nodejs
# uses: actions/setup-node@v2
# with:
# node-version: 16.x
# cache: "yarn"

# - name: Install
# run: yarn install

# - run: rm -rf node_modules/.prisma

# - name: Deploy Migrations
# run: npx prisma migrate deploy
# env:
# DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL }}
1 change: 1 addition & 0 deletions components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const links: { title: string; href: string; icon: JSX.Element }[] = [
{ title: "Rookie Teams", href: "/rookies", icon: <FaBolt /> },
{ title: "Insights", href: "/insights", icon: <FaChartLine /> },
{ title: "Marketplace", href: "/marketplace", icon: <FaTags /> },
{ title: "Utils", href: "/utils", icon: <FaUndo /> },
];

export const Navbar = (props: {
Expand Down
58 changes: 58 additions & 0 deletions lib/fetchTBA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,61 @@ export const fetchTBA = async (
.then((response: AxiosResponse<any, any>) => response.data)
.catch((error) => log("error", error));
};

export type TBATeam = {
key: string;
team_number: number;
nickname?: string;
name: string;
city?: string;
state_prov?: string;
country?: string;
address?: string;
postal_code?: string;
gmaps_place_id?: string;
gmaps_url?: string;
lat?: number;
lng?: number;
location_name?: string;
website?: string;
rookie_year?: number;
motto?: string;
};

export type TBAEvent = {
key: string;
name: string;
event_code: string;
event_type: number;
// district?:
city?: string;
state_prov?: string;
country?: string;
start_date: string;
end_date: string;
year: number;
short_name?: string;
event_type_string: string;
week?: number;
address?: string;
postal_code?: string;
gmaps_place_id?: string;
gmaps_url?: string;
lat?: number;
lng?: number;
location_name?: string;
timezone?: string;
website?: string;
first_event_id?: string;
first_event_code?: string;
webcasts?: {
channel: string;
type: string;
date?: string;
file?: string;
}[];
divison_keys?: string[];
parent_event_key?: string;
playoff_type?: number;
playoff_type_string?: string;
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"export-from-json": "^1.7.2",
"framer-motion": "^10.12.14",
"haversine-distance": "^1.2.1",
"lodash": "^4.17.21",
"next": "13.4.3",
"next-api-handler": "^0.4.10",
"next-auth": "^4.22.1",
"next-s3-upload": "^0.3.0",
"nsfwjs": "^2.4.2",
Expand All @@ -54,6 +56,7 @@
"devDependencies": {
"@commitlint/cli": "^17.6.3",
"@commitlint/config-conventional": "^17.6.3",
"@types/lodash": "^4.14.194",
"husky": "^8.0.3",
"prettier": "^2.8.8"
},
Expand Down
16 changes: 12 additions & 4 deletions pages/api/events/infoTeams.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { NextApiRequest, NextApiResponse } from "next";
import { fetchTBA } from "@/lib/fetchTBA";
import { AxiosResponse } from "axios";
import db from "@/lib/db";

export default async function getEventTeams(
req: NextApiRequest,
res: NextApiResponse
): Promise<void> {
const { event } = req.query;
const data: void | AxiosResponse<any, any> = await fetchTBA(
`event/${event}/teams`
);

res.status(200).send(data);
const rest = await db.team.findMany({
where: {
events: {
some: {
key: event as string,
},
},
},
});

res.status(200).send(rest);
}
Loading

1 comment on commit d8a9f9e

@vercel
Copy link

@vercel vercel bot commented on d8a9f9e May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.