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

Breakpoints stage 3 #1413

Merged
merged 15 commits into from
Apr 12, 2023
Prev Previous commit
Next Next commit
Add migrations
  • Loading branch information
istarkov committed Apr 12, 2023
commit d06e80702daecfb15d668a0fe125b9eb77eded4a
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PrismaClient } from "./client";

// NOTE ON IMPORTS:
//
// We want to be able to run old migrations at any point.
// For example, when we setting up a fresh database or making a reset.
//
// You shouldn't import code that may change later
// and become incompatible with the migration.
// It's better to copy it to the migration directory.

export default () => {
const client = new PrismaClient({
// Uncomment to see the queries in console as the migration runs
// log: ["query", "info", "warn", "error"],
});
return client.$transaction(
async (prisma) => {
/*
There are no minWidth: 0 inside other breakpoints anymore. Manually tested with
select distinct((breakpoints::jsonb #> '{1, minWidth}')::int) from "Build";

Below in jsonb syntax:
#> means select by path
#- remove at path
*/
await prisma.$executeRaw`
UPDATE "Build"
SET breakpoints = (breakpoints::jsonb #- '{0, minWidth}')::text
where (breakpoints::jsonb #> '{0, minWidth}')::int = 0;
`;
},
{ timeout: 1000 * 60 }
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// DO NOT EDIT THIS FILE!
// This is a copy of your schema.prisma that corresponds to the state of the database
// when all migrations up until this one are applied.
// It's used to generate a Prisma Client for the migration.

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
previewFeatures = ["views", "clientExtensions"]
// see commands.ts
output = "client"
}

datasource db {
provider = "postgres"
url = env("DATABASE_URL")
}

model Team {
id String @id @default(uuid())
users User[]
}

enum Location {
FS
REMOTE
}

enum UploadStatus {
UPLOADING
UPLOADED
}

model Asset {
id String @default(uuid()) // not unique!
projectId String
format String
size Int
name String
description String?
location Location
createdAt DateTime @default(now())
meta String @default("{}")
status UploadStatus @default(UPLOADED)

@@id([id, projectId])
}

model User {
id String @id @default(uuid())
email String? @unique
provider String?
image String?
username String?
createdAt DateTime @default(now())
team Team? @relation(fields: [teamId], references: [id])
teamId String?
projects Project[]
}

model Project {
id String @id @default(uuid())
createdAt DateTime @default(now())
title String
domain String @unique
user User? @relation(fields: [userId], references: [id])
userId String?
build Build[]
isDeleted Boolean @default(false)

@@unique([id, isDeleted])
@@unique([domain, isDeleted])
}

model Build {
id String @default(uuid())
createdAt DateTime @default(now())
pages String

project Project @relation(fields: [projectId], references: [id])
projectId String

isDev Boolean // exctly one is true per project
isProd Boolean // at most one is true per project (none if not published)

breakpoints String @default("[]")
styles String @default("[]")
styleSources String @default("[]")
styleSourceSelections String @default("[]")
props String @default("[]")
instances String @default("[]")

@@id([id, projectId])
}

model Breakpoints {
buildId String @id
values String @default("[]")
}

enum AuthorizationRelation {
viewers
editors
builders
}

model AuthorizationToken {
token String @default(uuid())
// No relation to Project, as the Authorization system is not tied to a project
projectId String
name String @default("")
relation AuthorizationRelation @default(viewers)
createdAt DateTime @default(now())

@@id([token, projectId])
}

// Dashboard
view DashboardProject {
id String @id @default(uuid())
createdAt DateTime @default(now())
title String
domain String
userId String?
isDeleted Boolean @default(false)
isPublished Boolean
}