Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage notes + feedback #1

Open
zxt-tzx opened this issue Dec 20, 2024 · 0 comments
Open

usage notes + feedback #1

zxt-tzx opened this issue Dec 20, 2024 · 0 comments

Comments

@zxt-tzx
Copy link

zxt-tzx commented Dec 20, 2024

I used this to manage my Supabase using SST. it works well but looking back, I think it might've been better to just manage the db connection using a secret instead.

Why?

  1. First, to get it to work, there are a bunch of foot guns like ensuring that the password doesn't contain special characters and writing code to replace the pooler URL to get the password in a Linkable state. It's also not super well-documented that, e.g., to get this to work, you need to have SUPABASE_ACCESS_TOKEN and SUPABASE_ORG_ID in your .env (poked into the codebase to find these)
See code
const supabasePassword = new random.RandomString("SupabasePassword", {
  special: false, // some special characters like `@` will break connection string
  length: 20,
});

// Create a new Supabase project
const db = new supabase.Project("app-db", {
  name: `app-db-${$app.stage}`,
  organizationId: supabaseOrgId,
  databasePassword: supabasePassword.result,
  region: $app.stage === "prod" ? "us-east-1" : "ap-southeast-1",
});

// Get the pooler URL and replace the password placeholder
const supabaseDbUrl = pulumi
  .all([db.id, db.databasePassword])
  .apply(async ([projectId, password]) => {
    const pooler = await supabase.getPooler({ projectRef: projectId });
    const poolerTransactionUrl = pooler.url["transaction"];
    if (!poolerTransactionUrl) {
      throw new Error("Failed to get pooler transaction URL");
    }
    return poolerTransactionUrl.replace("[YOUR-PASSWORD]", password);
  });

export const outputs = {
  dbUrn: db.urn,
};

export const database = new sst.Linkable("Supabase", {
  properties: {
    projectName: db.name,
    organizationId: db.organizationId,
    region: db.region,
    databasePassword: db.databasePassword,
    instanceSize: db.instanceSize,
    databaseUrl: supabaseDbUrl,
  },
});
  1. There are also various limitations like you can't change the instance size via the code etc. It's also not super clear whether the SST config's removal policy applied to Supabase (the doc says "S3 buckets and DynamoDB tables, and remove all other resources", which taken literally might not be what one expects!)

  2. Eventually, I decided to have multiple stages sharing a single database, and this was the ultimate reason that I removed this library and set the DB using the secret. You can also then have more flexibility over whether you want to use the pooler URL or a direct connection or sth else.

Hope this helps! Really appreciate the SST team building this integration all the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant