Supabase - Create a backend in less than 2 minutes. Start your project with a Postgres Database, Authentication, instant APIs, Realtime subscriptions and Storage.
pg_graphql - A native PostgreSQL extension adding GraphQL support. The extension keeps schema generation, query parsing, and resolvers all neatly contained on your database server requiring no external services.
Postgres Triggers and Postgres Functions - When votes are in, use triggers to invoke a Postgres function that calculates a post score to rank the feed
TypeScript - TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale.
graphql-code-generator - Generate code from your GraphQL schema and operations with a simple CLI
gql-tag-operations-preset - This code gen preset generates typings for your inline gql function usages, without having to manually specify import statements for the documents
urql - A highly customizable and versatile GraphQL client
Gravatar - Default avatar profile images from Gravatar
DEVELOPMENT COMMAND: yarn codegen && yarn workspace app dev --port $PORT
Development
Fetch latest GraphQL Schema
yarn codegen:fetch
Generate Types and Watch for Changes
yarn codegen:watch
Run server
yarn workspace app dev
Synchronize the GraphQL schema
Note: You need to call select graphql.rebuild_schema() manually to synchronize the GraphQL schema with the SQL schema after altering the SQL schema.
Manage Schema with dbmate
brew install dbmate
Setup .env with DATABASE_URL
Dump Schema
cd data
dbmate dump
Note: If pgdump fails due to row locks, a workaround is to grant the postgres role superuser permissions with ALTER USER postgres WITH SUPERUSER. After dumping the schema, you should reset the permissions using ALTER USER postgres WITH NOSUPERUSER. You can run these statements in the Superbase Dashboard SQL Editors.
Schema (Public)
Profile belongs to auth.users
Post
Comment belongs to Post and Profile
Vote belongs to Post (can have a direction of UP/DOWN)
direction enum is "UP" or "DOWN"
Constraints
Post url is unique
Vote is unique per Profile, Post (ie, you cannot vote more than once -- up or down)
Note: The schema includes the entire Supabase schema with auth, storage, functions, etc.
Seed Data
A data file for all Supabase Blog posts from the RSS feed can be found in ./data/seed/blog_posts.csv and can be loaded. Another file for comments is available as well.
请发表评论