question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to create WordPress datamodel?

See original GitHub issue

I’m using a MySQL database to store different content types (i.e companies, jobs, events, etc) which are all linked to each other and all have tags and hierarchical categories.

The structure of my database is very similar to the WordPress database, however, all the meta fields for each content type are stored in a separate *_Meta table instead of one single meta table.

Is it possible to do this in Prisma 2? If so, how should I define my datamodel so I can do a query like below? Screenshot_7

Below is my data model definition:

enum ContentStatus {
  ACTIVE
  DRAFT
  PENDING
  DELETED
 }
 
enum ContentType {
  COMPANY  
  JOB
  EVENT  
 }

model User {
  id: Int @id
  name: String!
  email: String @unique
  password: String!
  createdAt DateTime @default(now())
}

model Content {
  id: Int @id @unique
  title: String!
  description: String!
  excerpt: String!
  status: ContentStatus! @default(ACTIVE)
  slug: String @unique
  type: ContentType! @default(COMPANY)
  createdBy: User
  createdAt:  DateTime   @default(now())
  updatedAt:  DateTime   @updatedAt
}

model CompanyMeta {
  id: Int @id @unique
  content: Content
  events: Content! @relation(link: TABLE, name: "CompanyEventRelationships")
  incorporated: DateTime!
  email: String
  phone: String
  in_url: String
  fb_url: String
}

model EventMeta {
  id: Int @id @unique
  content: Content
  company: Content! @relation(link: TABLE, name: "CompanyEventRelationships")
  startDate: DateTime
  endDate: DateTime
  price: Int
  registrationUrl: String
}

model CompanyEventRelationships @relationTable {
  id: Int @id
  company: Content
  event: Content
}

enum TaxonomyType {
    CATEGORY
    TAG
 }

model Term {
  id: Int @id @unique
  name: String
  slug: String @unique
  term_group: Int @default(value: 0)
}

model TermTaxonomy {
  id: ID! @unique
  term: Term! @relation(link: INLINE) @default(value: 0)
  taxonomy: TaxonomyType!
  description: String?
  parent: Term! @relation(link: INLINE) @default(value: 0)
  count: Int @default(value: 0)
}

model TermRelationship {
  content: Content! @relation(link: INLINE) @default(value: 0)
  term_taxonomy: TermTaxonomy! @relation(link: INLINE) @default(value: 0)
  order: Int @default(value: 0)
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
pantharshit00commented, Aug 21, 2019

I went ahead and introspected a wordpress instance for you, this should give you a good idea:

datasource db {
  provider = "mysql"
  url      = "mysql://exampleuser:examplepass@localhost:2234/exampledb"
}

model WpComment {
  comment_ID         Int      @id
  commentAgent       String   @map("comment_agent")
  commentApproved    String   @map("comment_approved")
  commentAuthorEmail String   @map("comment_author_email")
  commentAuthorIP    String   @map("comment_author_IP")
  commentAuthorUrl   String   @map("comment_author_url")
  commentContent     String   @map("comment_content")
  commentDate        DateTime @map("comment_date")
  commentDateGmt     DateTime @map("comment_date_gmt")
  commentKarma       Int      @map("comment_karma")
  commentParent      Int      @map("comment_parent")
  commentPostID      Int      @map("comment_post_ID")
  commentType        String   @map("comment_type")
  userId             Int      @map("user_id")

  @@map("wp_comments")
}

model WpCommentmeta {
  meta_id   Int     @id
  commentId Int     @map("comment_id")
  metaKey   String? @map("meta_key")
  metaValue String? @map("meta_value")

  @@map("wp_commentmeta")
}

model WpLink {
  link_id         Int      @id
  linkDescription String   @map("link_description")
  linkImage       String   @map("link_image")
  linkName        String   @map("link_name")
  linkNotes       String   @map("link_notes")
  linkOwner       Int      @map("link_owner")
  linkRating      Int      @map("link_rating")
  linkRel         String   @map("link_rel")
  linkRss         String   @map("link_rss")
  linkTarget      String   @map("link_target")
  linkUpdated     DateTime @map("link_updated")
  linkUrl         String   @map("link_url")
  linkVisible     String   @map("link_visible")

  @@map("wp_links")
}

model WpOption {
  option_id   Int    @id
  autoload    String
  optionName  String @map("option_name") @unique
  optionValue String @map("option_value")

  @@map("wp_options")
}

model WpPost {
  ID                  Int      @id
  commentCount        Int      @map("comment_count")
  commentStatus       String   @map("comment_status")
  guid                String
  menuOrder           Int      @map("menu_order")
  pinged              String
  pingStatus          String   @map("ping_status")
  postAuthor          Int      @map("post_author")
  postContent         String   @map("post_content")
  postContentFiltered String   @map("post_content_filtered")
  postDate            DateTime @map("post_date")
  postDateGmt         DateTime @map("post_date_gmt")
  postExcerpt         String   @map("post_excerpt")
  postMimeType        String   @map("post_mime_type")
  postModified        DateTime @map("post_modified")
  postModifiedGmt     DateTime @map("post_modified_gmt")
  postName            String   @map("post_name")
  postParent          Int      @map("post_parent")
  postPassword        String   @map("post_password")
  postStatus          String   @map("post_status")
  postTitle           String   @map("post_title")
  postType            String   @map("post_type")
  toPing              String   @map("to_ping")

  @@map("wp_posts")
}

model WpPostmeta {
  meta_id   Int     @id
  metaKey   String? @map("meta_key")
  metaValue String? @map("meta_value")
  postId    Int     @map("post_id")

  @@map("wp_postmeta")
}

model WpTerm {
  term_id   Int    @id
  name      String
  slug      String
  termGroup Int    @map("term_group")

  @@map("wp_terms")
}

model WpTermRelationship {
  /// Multiple ID fields (compound indexes) are not supported
  object_id        Int @id
  /// Multiple ID fields (compound indexes) are not supported
  term_taxonomy_id Int @id
  termOrder        Int @map("term_order")

  @@map("wp_term_relationships")
}

model WpTermTaxonomy {
  term_taxonomy_id Int    @id
  count            Int
  description      String
  parent           Int
  taxonomy         String
  termId           Int    @map("term_id")

  @@map("wp_term_taxonomy")
}

model WpTermmeta {
  meta_id   Int     @id
  metaKey   String? @map("meta_key")
  metaValue String? @map("meta_value")
  termId    Int     @map("term_id")

  @@map("wp_termmeta")
}

model WpUser {
  ID                Int      @id
  displayName       String   @map("display_name")
  userActivationKey String   @map("user_activation_key")
  userEmail         String   @map("user_email")
  userLogin         String   @map("user_login")
  userNicename      String   @map("user_nicename")
  userPass          String   @map("user_pass")
  userRegistered    DateTime @map("user_registered")
  userStatus        Int      @map("user_status")
  userUrl           String   @map("user_url")

  @@map("wp_users")
}

model WpUsermeta {
  umeta_id  Int     @id
  metaKey   String? @map("meta_key")
  metaValue String? @map("meta_value")
  userId    Int     @map("user_id")

  @@map("wp_usermeta")
}
1reaction
pantharshit00commented, Aug 22, 2019

I think you are considering Prisma to be a GraphQL ORM which it is not.

You will need to implement these in your GraphQL server.

But I do think we can provide an example for this once the Relay style pagination part of the photon is ready(https://github.com/prisma/specs/blob/photonjs-improvements/specs/PhotonJS.md#todo-withpageinfo)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create datamodel for WordPress taxonomies and terms
Hi,. I'm planning to create the same WordPress database structure in a MySQL prismaDB. Has anybody implemented a datamodel for WordPress ...
Read more >
custom data model - link and populate from admin backend
My question is, given I am doing some complex functions that require models and queries that don't fit neatly into the WP conception...
Read more >
Creating a Custom Table with PHP in WordPress
Creating a new table in the database used by WordPress is as simple as writing the SQL statement to create it, and then...
Read more >
Beginner's Guide To WordPress Database Schema & Structure
A database is created whenever you build a WordPress website. Everything on your WordPress website, be it posts, custom post type, pages, ...
Read more >
WordPress – Behind the Scenes, Part 2 - Vertabelo
The model has to be flexible enough to accommodate all the different plugins. Of course, plugin creators can add custom tables for specific ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found