diff --git a/scripts/managed/new_accnt.py b/scripts/managed/new_accnt.py new file mode 100644 index 0000000..192f0d7 --- /dev/null +++ b/scripts/managed/new_accnt.py @@ -0,0 +1,49 @@ +from time import sleep +import secrets + +import supabase + + +MAIN_SUPABASE_URL = "" +MAIN_SUPABASE_SERVICE_ROLE = "" +MAIN_SUPABASE_CLIENT = supabase.create_client(MAIN_SUPABASE_URL, MAIN_SUPABASE_SERVICE_ROLE) + + +def get_latest_account_number(): + latest_account = MAIN_SUPABASE_CLIENT.auth.admin.list_users()[0] + if latest_account is None: + return 1 + if not "account_number" in latest_account.user_metadata: + return 1 + else: + return latest_account.user_metadata["account_number"] + +def main(): + user_real_email = input("Enter user real email: ") + + new_account_number = get_latest_account_number() + 1 + formatted_number = str(new_account_number).zfill(4) + email = f'{formatted_number}@adeus.ai' + password = secrets.token_urlsafe(13) + + res = MAIN_SUPABASE_CLIENT.auth.admin.create_user( + attributes={ + "email": email, + "password": password, + "email_confirm": True, + "user_metadata": { + "account_number": new_account_number, + "user_real_email": user_real_email + } + } + ) + + + print("\n\n\n\n\n\n--------------\nDetails: ") + print(f"EMAIL: {email}") + print(f"PASS: {password}") + print("--------------\n\n\n\n\n\n\n") + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/managed/requirements.txt b/scripts/managed/requirements.txt new file mode 100644 index 0000000..279ed29 --- /dev/null +++ b/scripts/managed/requirements.txt @@ -0,0 +1 @@ +supabase==2.4.0 \ No newline at end of file diff --git a/supabase/migrations/20240326142114_remote_schema.sql b/supabase/migrations/20240326142114_remote_schema.sql new file mode 100644 index 0000000..140be7e --- /dev/null +++ b/supabase/migrations/20240326142114_remote_schema.sql @@ -0,0 +1,35 @@ +drop policy "Enable access for all authed" on "public"."conversations"; + +alter table "public"."conversations" add column "auth_id" uuid not null default auth.uid(); + +alter table "public"."records" add column "auth_id" uuid not null default auth.uid(); + +alter table "public"."records" enable row level security; + +alter table "public"."conversations" add constraint "public_conversations_user_id_fkey" FOREIGN KEY (auth_id) REFERENCES auth.users(id) ON DELETE CASCADE not valid; + +alter table "public"."conversations" validate constraint "public_conversations_user_id_fkey"; + +alter table "public"."records" add constraint "public_records_user_id_fkey" FOREIGN KEY (auth_id) REFERENCES auth.users(id) ON DELETE CASCADE not valid; + +alter table "public"."records" validate constraint "public_records_user_id_fkey"; + +create policy "users can only see and do their own things" +on "public"."conversations" +as permissive +for all +to authenticated +using ((auth.uid() = auth_id)) +with check ((auth.uid() = auth_id)); + + +create policy "users can only see and do their own things" +on "public"."records" +as permissive +for all +to authenticated +using ((auth.uid() = auth_id)) +with check ((auth.uid() = auth_id)); + + +