Giter Site home page Giter Site logo

ecsl's Introduction

supabase-sveltekit

Developing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

You may need to update you .env file

Database

Create table for Districts

create table
  public.districts (
    id uuid not null default gen_random_uuid (),
    created_at timestamp with time zone null default now(),
    district_name text null,
    constraint districts_pkey primary key (id)
  ) tablespace pg_default;

Create table for Political Parties

create table
  public.political_parties (
    id uuid not null default gen_random_uuid (),
    created_at timestamp with time zone null default now(),
    party_name text null,
    party_colour text null,
    constraint political_parties_pkey primary key (id)
  ) tablespace pg_default;

Create table for results

create table
  public.results (
    id uuid not null default gen_random_uuid (),
    created_at timestamp with time zone null default now(),
    agent_id uuid null,
    political_party_id uuid null,
    district text null,
    total_votes integer null,
    district_id uuid null,
    constraint results_pkey primary key (id),
    constraint results_agent_id_fkey foreign key (agent_id) references profiles (id) on delete restrict,
    constraint results_district_id_fkey foreign key (district_id) references districts (id),
    constraint results_political_party_id_fkey foreign key (political_party_id) references political_parties (id) on delete restrict
  ) tablespace pg_default;

Create table for users

create table
  public.profiles (
    id uuid not null,
    updated_at timestamp with time zone null,
    username text null,
    full_name text null,
    avatar_url text null,
    website text null,
    political_party_id uuid null,
    district_id uuid null,
    user_role text null default 'agent'::text,
    constraint profiles_pkey primary key (id),
    constraint profiles_username_key unique (username),
    constraint profiles_district_id_fkey foreign key (district_id) references districts (id),
    constraint profiles_id_fkey foreign key (id) references auth.users (id) on delete cascade,
    constraint profiles_political_party_id_fkey foreign key (political_party_id) references political_parties (id),
    constraint username_length check ((char_length(username) >= 3))
  ) tablespace pg_default;

You need to edit the handle_new_user function

In the supabase dashboard, click Database > Functions.

Edit handle_new_user function with the code below:

begin
  insert into public.profiles (id, full_name, avatar_url, political_party_id, district_id)
  values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url', (new.raw_user_meta_data->>'political_party_id')::uuid, (new.raw_user_meta_data->>'district_id')::uuid);
  return new;
end;

ecsl's People

Contributors

javapr0 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.