Skip to content

Commit

Permalink
Validate Migration of Import Export Data (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisaha1 committed Mar 9, 2022
1 parent e39ed75 commit 88a16fe
Show file tree
Hide file tree
Showing 13 changed files with 635 additions and 125 deletions.
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

0 comments on commit 88a16fe

Please sign in to comment.