Skip to content

Latest commit

 

History

History
82 lines (65 loc) · 3.41 KB

run-supabase-postgres-instance.md

File metadata and controls

82 lines (65 loc) · 3.41 KB

How to create a PostgreSQL database on Supabase?

  1. First, visit supabase.com and sign up using your GitHub account. supabase-sign-up

  2. Once signed up, click on the "New project" button. New supabase Project

  3. Enter the following settings, then click the "Create New Project" button:

Name: Pikachu # Choose any name
Database Password: greyninja1234_A # For testing, use "greyninja1234_A". In production, use a strong password.
Region: West US (North California) # Select the region closest to your server for best performance.

Enter supabase Settings

  1. Wait a few minutes for the project to be created. wait project

  2. Navigate to "Project settings" > "Database" and copy the connection string. connection string

  3. In Vscode, create a new file main.py and paste the following code to test the connection:

from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Create a database connection URL
db_url = 'SUPABASE_CONNECTION_STRING'
engine = create_engine(db_url.replace("postgres://", "postgresql://", 1))
Session = sessionmaker(bind=engine)
session = Session()

# Define a model
Base = declarative_base()
class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)

# Create the table
Base.metadata.create_all(engine)

# Insert a record
new_user = User(name='John Doe')
session.add(new_user)
session.commit()

# Query records
users = session.query(User).all()
for user in users:
    print(user.id, user.name)

# Print a success message
print("Hurray! database connection is working.")
  1. In the pasted code:

    • Replace SUPABASE_CONNECTION_STRING with the connection string you copied from the Supabase dashboard.
    • In the connection string, replace [YOUR-PASSWORD] with the password you set when creating the instance (e.g., greyninja1234_A).
  2. Run the code. You should see the following output:

1 John Doe
Hurray! database connection is working.

supa Output

  1. Finally, to use the PostgreSQL database in Botasaurus:
    • Open the backend/scrapers.py file.
    • Add the following line, replacing SUPABASE_CONNECTION_STRING with your connection string:
    Server.set_database_url('SUPABASE_CONNECTION_STRING')
    Use in Botasaurus supa

How to delete the Supabase project?

Deleting the project will permanently erase all data associated with it. Make sure to download any important data before proceeding.

To delete the project, go to "Project settings" > "General" and click on the "Delete Project" button. Delete supabase