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

Use a prisma schema with TinyBase so you can sync with a hosted postgres db #56

Open
dillondotzip opened this issue Feb 27, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request roadmap You should be able to see this on https://github.com/orgs/tinyplex/projects/1 working on it Please be patient!

Comments

@dillondotzip
Copy link

I'd like to have a single prisma schema that can be used with the inside setTablesSchema().

An example schema.primsa file:

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

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

generator client {
  provider = "prisma-client-js"
}

// --------------------------------------

model User {
  id             Int          @id @default(cuid())
  createdAt      DateTime     @default(now())
  updatedAt      DateTime     @updatedAt
  email          String       @unique
  hashedPassword String?
  role           String       @default("USER")
  avatar         Json?
  tokens         Token[]
  sessions       Session[]
  todos            Todo[]
}

model Session {
  id                 Int       @id @default(cuid())
  createdAt          DateTime  @default(now())
  updatedAt          DateTime  @updatedAt
  expiresAt          DateTime?
  handle             String    @unique
  hashedSessionToken String?
  antiCSRFToken      String?
  publicData         String?
  privateData        String?
  user   User? @relation(fields: [userId], references: [id])
  userId Int?
}

model Token {
  id          Int       @id @default(cuid())
  createdAt   DateTime  @default(now())
  updatedAt   DateTime  @updatedAt
  hashedToken String
  lastFour String?
  type        TokenType
  expiresAt   DateTime
  sentTo      String?
  user   User? @relation(fields: [userId], references: [id])
  userId Int?
  @@unique([hashedToken, type])
}

enum TokenType {
  RESET_PASSWORD
  INVITE_TOKEN
  PUBLIC_KEY
  SECRET_KEY
}

model Todo {
  id         String   @id @default(cuid())
  createdAt  DateTime @default(now())
  modifiedAt DateTime @default(now())
  name String
  slug String @unique
  user   User @relation(fields: [userId], references: [id])
  userId Int
}

Notice the @unqiue & @relation helpers

@jamesgpearce jamesgpearce self-assigned this Sep 27, 2023
@jamesgpearce jamesgpearce added the enhancement New feature or request label Sep 27, 2023
@jamesgpearce jamesgpearce added the roadmap You should be able to see this on https://github.com/orgs/tinyplex/projects/1 label Nov 9, 2023
@andrictham
Copy link

andrictham commented Feb 23, 2024

As a start, it would be helpful if we could type our Tinybase tables by passing in generated Prisma types as a type parameter to Tinybase’s setTablesSchema function.

Alternatively, an officially-supported Prisma generator which auto-generates Tinybase schemas would be extremely helpful to DRY up types.

Right now, it’s a pain to write a schema twice: once in Prisma, and another time when setting up Tinybase using setSchema or setTablesSchema. Getting them to sync up is a pain.

Even if the data doesn’t sync up, having the types sync up with Prisma would be a massive DX improvement.

@jamesgpearce
Copy link
Contributor

I am going to focus on schemas in 5.1 and 5.2. Hang in there!

@jamesgpearce jamesgpearce moved this from Planned to In Progress in The TinyBase Roadmap Jul 5, 2024
@jamesgpearce jamesgpearce added the working on it Please be patient! label Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request roadmap You should be able to see this on https://github.com/orgs/tinyplex/projects/1 working on it Please be patient!
Projects
Status: In Progress
Development

No branches or pull requests

3 participants