Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate Migration of Import Export Data #251

Merged
merged 4 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"migrate": "prisma migrate dev --name init",
"typecheck": "yarn tsc",
"prisma:generate": "scripts/generatePrisma.sh",
"prisma:studio": "scripts/studio.sh",
"resetDemo": "ts-node -r tsconfig-paths/register --transpile-only ./src/resetDemo.ts"
},
"dependencies": {
Expand All @@ -26,9 +27,12 @@
"@sentry/nextjs": "^6.15.0",
"@tinymce/tinymce-react": "^3.13.0",
"@types/bcryptjs": "^2.4.2",
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"antd": "^4.18.8",
"apollo-server": "^3.6.3",
"apollo-server-micro": "2.25.0",
"axios": "^0.26.0",
"bcryptjs": "^2.4.3",
"cheerio": "^1.0.0-rc.10",
"cloudinary": "^1.28.1",
Expand Down
8 changes: 8 additions & 0 deletions scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if [ "$NODE_ENV" == "production" ]
then
export $(echo $(cat .env.production.local | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)
else
export $(echo $(cat .env.development.local | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)
fi
7 changes: 1 addition & 6 deletions scripts/generatePrisma.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/bash

if [ "$NODE_ENV" == "production" ]
then
export $(echo $(cat .env.production.local | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)
else
export $(echo $(cat .env.development.local | sed 's/#.*//g' | sed 's/\r//g' | xargs) | envsubst)
fi
. $(dirname "$0")/env.sh

PRISMA_FILE="schema.prisma"

Expand Down
11 changes: 11 additions & 0 deletions scripts/studio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

. $(dirname "$0")/env.sh

PRISMA_FILE="schema.prisma"

if [[ "$DATABASE_URL" =~ ^mysql.* ]]; then
export PRISMA_FILE="schema_mysql.prisma"
fi

npx prisma studio --schema prisma/$PRISMA_FILE
25 changes: 25 additions & 0 deletions src/components/import-export/importExportTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Author, Post, Setting, Subscriber, Tag, Upload } from "@prisma/client";

export interface ITagSanitized {
name: string;
slug: string;
}

type SanitizedAuthor = Omit<
Author,
"id" | "password" | "role_id" | "verify_attempt_left"
>;
export interface IAuthorData extends SanitizedAuthor {
setting: Omit<Setting, "id" | "author_id" | "client_token">;
subscribers: Omit<Subscriber, "author_id" | "id" | "verify_attempt_left">[];
uploads: Omit<Upload, "id" | "author_id">[];
posts: (Omit<Post, "id" | "author_id"> & {
tags: Omit<Tag, "id">[];
})[];
}

export interface IImportExportData {
authors: {
[email: string]: IAuthorData;
};
}
Loading