Kurt/upgrade rw 38 (#575)

* Upgrade to rw 38

* Prisma migrate after V3 upgrade

* rw 0.38.1
This commit was merged in pull request #575.
This commit is contained in:
Kurt Hutten
2021-11-13 11:53:42 +11:00
committed by GitHub
parent a62c5bce03
commit e9859d85b8
9 changed files with 1465 additions and 1546 deletions

View File

@@ -0,0 +1,56 @@
-- DropForeignKey
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_projectId_fkey";
-- DropForeignKey
ALTER TABLE "Comment" DROP CONSTRAINT "Comment_userId_fkey";
-- DropForeignKey
ALTER TABLE "Project" DROP CONSTRAINT "Project_userId_fkey";
-- DropForeignKey
ALTER TABLE "ProjectReaction" DROP CONSTRAINT "ProjectReaction_projectId_fkey";
-- DropForeignKey
ALTER TABLE "ProjectReaction" DROP CONSTRAINT "ProjectReaction_userId_fkey";
-- DropForeignKey
ALTER TABLE "SocialCard" DROP CONSTRAINT "SocialCard_projectId_fkey";
-- DropForeignKey
ALTER TABLE "SubjectAccessRequest" DROP CONSTRAINT "SubjectAccessRequest_userId_fkey";
-- AddForeignKey
ALTER TABLE "Project" ADD CONSTRAINT "Project_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "SocialCard" ADD CONSTRAINT "SocialCard_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ProjectReaction" ADD CONSTRAINT "ProjectReaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ProjectReaction" ADD CONSTRAINT "ProjectReaction_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "Comment" ADD CONSTRAINT "Comment_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "SubjectAccessRequest" ADD CONSTRAINT "SubjectAccessRequest_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- RenameIndex
ALTER INDEX "Project.title_userId_unique" RENAME TO "Project_title_userId_key";
-- RenameIndex
ALTER INDEX "ProjectReaction.emote_userId_projectId_unique" RENAME TO "ProjectReaction_emote_userId_projectId_key";
-- RenameIndex
ALTER INDEX "SocialCard.projectId_unique" RENAME TO "SocialCard_projectId_key";
-- RenameIndex
ALTER INDEX "User.email_unique" RENAME TO "User_email_key";
-- RenameIndex
ALTER INDEX "User.userName_unique" RENAME TO "User_userName_key";

View File

@@ -1,250 +0,0 @@
/* eslint-disable no-console */
const { PrismaClient } = require('@prisma/client')
const dotenv = require('dotenv')
dotenv.config()
const db = new PrismaClient()
async function main() {
// Seed data is database data that needs to exist for your app to run.
// Ideally this file should be idempotent: running it multiple times
// will result in the same database state (usually by checking for the
// existence of a record before trying to create it). For example:
//
// const existing = await db.user.findMany({ where: { email: 'admin@email.com' }})
// if (!existing.length) {
// await db.user.create({ data: { name: 'Admin', email: 'admin@email.com' }})
// }
const users = [
{
id: "a2b21ce1-ae57-43a2-b6a3-b6e542fd9e60",
userName: "local-user-1",
name: "local 1",
email: "localUser1@kurthutten.com"
},
{
id: "682ba807-d10e-4caf-bf28-74054e46c9ec",
userName: "local-user-2",
name: "local 2",
email: "localUser2@kurthutten.com"
},
{
id: "5cea3906-1e8e-4673-8f0d-89e6a963c096",
userName: "local-admin-2",
name: "local admin",
email: "localAdmin@kurthutten.com"
},
]
let existing
existing = await db.user.findMany({ where: { id: users[0].id }})
if(!existing.length) {
await db.user.create({
data: users[0],
})
}
existing = await db.user.findMany({ where: { id: users[1].id }})
if(!existing.length) {
await db.user.create({
data: users[1],
})
}
const projects = [
{
title: 'demo-project1',
description: '# can be markdown',
mainImage: 'CadHub/kjdlgjnu0xmwksia7xox',
code: getOpenScadHingeCode(),
cadPackage: 'openscad',
user: {
connect: {
id: users[0].id,
},
},
},
{
title: 'demo-project2',
description: '## [hey](www.google.com)',
user: {
connect: {
id: users[1].id,
},
},
},
]
existing = await db.project.findMany({where: { title: projects[0].title}})
if(!existing.length) {
await db.project.create({
data: projects[0],
})
}
existing = await db.project.findMany({where: { title: projects[1].title}})
if(!existing.length) {
const result = await db.project.create({
data: projects[1],
})
await db.project.create({
data: {
...projects[1],
title: `${projects[1].title} fork`,
forkedFrom: {
connect: {
id: result.id,
},
},
},
})
}
const aProject = await db.project.findUnique({where: {
title_userId: {
title: projects[0].title,
userId: users[0].id,
}
}})
await db.comment.create({
data: {
text: "nice project, I like it",
userId: users[0].id,
projectId: aProject.id,
// user: {connect: { id: users[0].id}},
// project: {connect: { id: aProject.id}},
}
})
await db.projectReaction.create({
data: {
emote: "❤️",
userId: users[0].id,
projectId: aProject.id,
// user: {connect: { id: users[0].id}},
// project: {connect: { id: aProject.id}},
}
})
console.info('No data to seed. See api/prisma/seeds.js for info.')
}
main()
.catch((e) => console.error(e))
.finally(async () => {
await db.$disconnect()
})
function getOpenScadHingeCode () {
return `
baseWidth=15; // [0.1:0.1:50]
hingeLength=30; // [0.1:0.1:50]
// Hole mant mounting holes per half.
mountingHoleCount=3; // [1:20]
baseThickness=3; // [0.1:0.1:20]
pivotRadius=5; // [0.1:0.1:20]
// Pin that the hinge pivots on.
pinRadius=2; // [0.1:0.1:20]
mountingHoleRadius=1.5; // [0.1:0.1:10]
// How far away the hole is from the egde.
mountingHoleEdgeOffset=4; // [0:50]
// Depending on the accuracy of your printer this may need to be increased in order for print in place to work.
clearance=0.2; // [0.05:0.01:1]
// Radius difference in the ivot taper to stop the hinge from falling apart. Should be increased with large clearance values.
pinTaper=0.25; // [0.1:0.1:2]
// calculated values
hingeHalfExtrudeLength=hingeLength/2-clearance/2;
mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
(mountingHoleCount-1);
module costomizerEnd() {}
$fn=30;
tiny=0.005;
// modules
module hingeBaseProfile() {
translate([pivotRadius,0,0]){
square([baseWidth,baseThickness]);
}
}
module hingeBodyHalf() {
difference() {
union() {
linear_extrude(hingeHalfExtrudeLength){
offset(1)offset(-2)offset(1){
translate([0,pivotRadius,0]){
circle(pivotRadius);
}
square([pivotRadius,pivotRadius]);
hingeBaseProfile();
}
}
linear_extrude(hingeLength){
offset(1)offset(-1)hingeBaseProfile();
}
}
plateHoles();
}
}
module pin(rotateY, radiusOffset) {
translate([0,pivotRadius,hingeHalfExtrudeLength+tiny]){
rotate([0,rotateY,0]) {
cylinder(
h=hingeLength/2+clearance/2,
r1=pinRadius+radiusOffset,
r2=pinRadius+pinTaper+radiusOffset
);
}
}
}
module hingeHalfFemale() {
difference() {
hingeBodyHalf();
pin(rotateY=180, radiusOffset=clearance);
}
}
module hingeHalfMale() {
translate([0,0,hingeLength]) {
rotate([0,180,0]) {
hingeBodyHalf();
pin(rotateY=0, radiusOffset=0);
}
}
}
module plateHoles() {
for(i=[0:mountingHoleCount-1]){
translate([
baseWidth/2+pivotRadius,
-baseThickness,
i*mountingHoleMoveIncrement+mountingHoleEdgeOffset
]){
rotate([-90,0,0]){
cylinder(r=mountingHoleRadius,h=baseThickness*4);
}
}
}
}
// using high-level modules
translate([0,0,-15]) {
hingeHalfFemale();
hingeHalfMale();
}
`
}

View File

@@ -3,8 +3,8 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@redwoodjs/api": "^0.37.5", "@redwoodjs/api": "^0.38.1",
"@redwoodjs/graphql-server": "^0.37.5", "@redwoodjs/graphql-server": "^0.38.1",
"@sentry/node": "^6.5.1", "@sentry/node": "^6.5.1",
"axios": "^0.21.1", "axios": "^0.21.1",
"cloudinary": "^1.23.0", "cloudinary": "^1.23.0",

View File

@@ -12,7 +12,7 @@
"aws-emulate": "nodemon ./api/src/docker/aws-emulator.js" "aws-emulate": "nodemon ./api/src/docker/aws-emulator.js"
}, },
"devDependencies": { "devDependencies": {
"@redwoodjs/core": "^0.37.5" "@redwoodjs/core": "^0.38.1"
}, },
"eslintConfig": { "eslintConfig": {
"extends": "@redwoodjs/eslint-config", "extends": "@redwoodjs/eslint-config",
@@ -30,7 +30,10 @@
} }
}, },
"engines": { "engines": {
"node": ">=14", "node": ">=14.x <=16.x",
"yarn": ">=1.15" "yarn": ">=1.15"
},
"prisma": {
"seed": "yarn rw exec seed"
} }
} }

View File

@@ -7,7 +7,7 @@
[web] [web]
port = 8910 port = 8910
apiProxyPath = "/.netlify/functions" apiUrl = "/.netlify/functions"
includeEnvironmentVariables = [ includeEnvironmentVariables = [
'GOOGLE_ANALYTICS_ID', 'GOOGLE_ANALYTICS_ID',
'CLOUDINARY_API_KEY', 'CLOUDINARY_API_KEY',

235
app/scripts/seed.ts Normal file
View File

@@ -0,0 +1,235 @@
import type { Prisma } from '@prisma/client'
import { db } from '$api/src/lib/db'
export default async () => {
try {
const users = [
{
id: "a2b21ce1-ae57-43a2-b6a3-b6e542fd9e60",
userName: "local-user-1",
name: "local 1",
email: "localUser1@kurthutten.com"
},
{
id: "682ba807-d10e-4caf-bf28-74054e46c9ec",
userName: "local-user-2",
name: "local 2",
email: "localUser2@kurthutten.com"
},
{
id: "5cea3906-1e8e-4673-8f0d-89e6a963c096",
userName: "local-admin-2",
name: "local admin",
email: "localAdmin@kurthutten.com"
},
]
let existing
existing = await db.user.findMany({ where: { id: users[0].id }})
if(!existing.length) {
await db.user.create({
data: users[0],
})
}
existing = await db.user.findMany({ where: { id: users[1].id }})
if(!existing.length) {
await db.user.create({
data: users[1],
})
}
const projects = [
{
title: 'demo-project1',
description: '# can be markdown',
mainImage: 'CadHub/kjdlgjnu0xmwksia7xox',
code: getOpenScadHingeCode(),
cadPackage: 'openscad',
user: {
connect: {
id: users[0].id,
},
},
},
{
title: 'demo-project2',
description: '## [hey](www.google.com)',
user: {
connect: {
id: users[1].id,
},
},
},
]
existing = await db.project.findMany({where: { title: projects[0].title}})
if(!existing.length) {
await db.project.create({
data: projects[0],
})
}
existing = await db.project.findMany({where: { title: projects[1].title}})
if(!existing.length) {
const result = await db.project.create({
data: projects[1],
})
await db.project.create({
data: {
...projects[1],
title: `${projects[1].title}-fork`,
forkedFrom: {
connect: {
id: result.id,
},
},
},
})
}
const aProject = await db.project.findUnique({where: {
title_userId: {
title: projects[0].title,
userId: users[0].id,
}
}})
await db.comment.create({
data: {
text: "nice project, I like it",
userId: users[0].id,
projectId: aProject.id,
// user: {connect: { id: users[0].id}},
// project: {connect: { id: aProject.id}},
}
})
await db.projectReaction.create({
data: {
emote: "❤️",
userId: users[0].id,
projectId: aProject.id,
// user: {connect: { id: users[0].id}},
// project: {connect: { id: aProject.id}},
}
})
} catch (error) {
console.warn('Please define your seed data.')
console.error(error)
}
}
function getOpenScadHingeCode () {
return `
baseWidth=15; // [0.1:0.1:50]
hingeLength=30; // [0.1:0.1:50]
// Hole mant mounting holes per half.
mountingHoleCount=3; // [1:20]
baseThickness=3; // [0.1:0.1:20]
pivotRadius=5; // [0.1:0.1:20]
// Pin that the hinge pivots on.
pinRadius=2; // [0.1:0.1:20]
mountingHoleRadius=1.5; // [0.1:0.1:10]
// How far away the hole is from the egde.
mountingHoleEdgeOffset=4; // [0:50]
// Depending on the accuracy of your printer this may need to be increased in order for print in place to work.
clearance=0.2; // [0.05:0.01:1]
// Radius difference in the ivot taper to stop the hinge from falling apart. Should be increased with large clearance values.
pinTaper=0.25; // [0.1:0.1:2]
// calculated values
hingeHalfExtrudeLength=hingeLength/2-clearance/2;
mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
(mountingHoleCount-1);
module costomizerEnd() {}
$fn=30;
tiny=0.005;
// modules
module hingeBaseProfile() {
translate([pivotRadius,0,0]){
square([baseWidth,baseThickness]);
}
}
module hingeBodyHalf() {
difference() {
union() {
linear_extrude(hingeHalfExtrudeLength){
offset(1)offset(-2)offset(1){
translate([0,pivotRadius,0]){
circle(pivotRadius);
}
square([pivotRadius,pivotRadius]);
hingeBaseProfile();
}
}
linear_extrude(hingeLength){
offset(1)offset(-1)hingeBaseProfile();
}
}
plateHoles();
}
}
module pin(rotateY, radiusOffset) {
translate([0,pivotRadius,hingeHalfExtrudeLength+tiny]){
rotate([0,rotateY,0]) {
cylinder(
h=hingeLength/2+clearance/2,
r1=pinRadius+radiusOffset,
r2=pinRadius+pinTaper+radiusOffset
);
}
}
}
module hingeHalfFemale() {
difference() {
hingeBodyHalf();
pin(rotateY=180, radiusOffset=clearance);
}
}
module hingeHalfMale() {
translate([0,0,hingeLength]) {
rotate([0,180,0]) {
hingeBodyHalf();
pin(rotateY=0, radiusOffset=0);
}
}
}
module plateHoles() {
for(i=[0:mountingHoleCount-1]){
translate([
baseWidth/2+pivotRadius,
-baseThickness,
i*mountingHoleMoveIncrement+mountingHoleEdgeOffset
]){
rotate([-90,0,0]){
cylinder(r=mountingHoleRadius,h=baseThickness*4);
}
}
}
}
// using high-level modules
translate([0,0,-15]) {
hingeHalfFemale();
hingeHalfMale();
}
`
}

View File

@@ -20,10 +20,10 @@
"@react-three/drei": "^7.3.1", "@react-three/drei": "^7.3.1",
"@react-three/fiber": "^7.0.5", "@react-three/fiber": "^7.0.5",
"@react-three/postprocessing": "^2.0.5", "@react-three/postprocessing": "^2.0.5",
"@redwoodjs/auth": "^0.37.5", "@redwoodjs/auth": "^0.38.1",
"@redwoodjs/forms": "^0.37.5", "@redwoodjs/forms": "^0.38.1",
"@redwoodjs/router": "^0.37.5", "@redwoodjs/router": "^0.38.1",
"@redwoodjs/web": "^0.37.5", "@redwoodjs/web": "^0.38.1",
"@sentry/browser": "^6.5.1", "@sentry/browser": "^6.5.1",
"@tailwindcss/aspect-ratio": "0.2.1", "@tailwindcss/aspect-ratio": "0.2.1",
"axios": "^0.21.1", "axios": "^0.21.1",

View File

@@ -341,3 +341,9 @@
padding-bottom: 0; padding-bottom: 0;
} }
} }
.rw-input-error:focus {
outline: none;
border-color: #c53030;
box-shadow: 0 0 5px #c53030;
}

File diff suppressed because it is too large Load Diff