Supabase migration scripts
Danger zone
sql/0-reset.sql
Can only be run from Supabase dashboard
sql/1-extensions.sql
Installs the required extensions;
postgismoddatetime
sql/2-types.sql
Creates up the types we need;
feed_postprofile_gender
sql/3-tables.sql
Creates the tables for our schema;
profilespostsvotescommentsconversationsconversation_membersmessages
sql/4-triggers.sql
Sets up the triggers we need;
on_auth_user_createdmessages_update_timestamp_on_conversationsvotes_update_timestamp
sql/5-policies.sql
Sets up the row level security policies we need on our tables;
users can view all profilesusers can update their own profiles
users can create postsusers can view all postsusers can update their own postsusers can delete their own posts
users can create votesusers can view all votesusers can update their own votesusers can delete their own votes
users can create commentsusers can view all commentsusers can update their own commentsusers can delete their own comments
users can view their own conversations
users can view their own conversation members
users can create messagesusers can view messages in their conversations
sql/6-functions.sql
Creates the stored procedures we need;
feed_popularfeed_latestfeed_nearbyfeed_userfetch_postcreate_poststart_conversationupdate_conversation_timestamphandle_new_user
Not used anymore
sql/7-views.sql
sql/8-seed.sql
Generates the SQL dump we can import into our database.
- Creates 1,000 users
- Creates 1,000 posts
- Creates 100,000 votes
- Creates 10,000 comments
There's a seed generator script, powered by lodash and chance.
yarn generate will compile the data into SQL files.
If you make any changes to the schema, you need to yarn clean to delete the source JSON files so updated data can be generated with yarn generate.
Seed data is cached in JSON files so we can reference post and user ids for votes and comments.