supabase-community / seed

Automatically seed your database with production-like dummy data based on your schema for local development and testing.
MIT License
462 stars 17 forks source link

Generated userModels.js can't handle columns with question marks #190

Open mrjogo opened 2 months ago

mrjogo commented 2 months ago

Some of Supabase's built-in tables (specifically _analytics.users) have column names with question marks (ie, lifetime_plan?). Seed's codegen doesn't handle it properly, and generates the following invalid javascript in userModels.js:

billing_accounts: {
  data: {
    id: null,
    latest_successful_stripe_session: fallbackFunctionTagger(({ seed, options }) => { return ({ [copycat.word(seed)]: copycat.words(seed) }) }),
    stripe_customer: fallbackFunctionTagger(({ seed, options }) => { return copycat.sentence(seed, options).slice(0, 255) }),
    user_id: fallbackFunctionTagger(({ seed, options }) => { return copycat.int(seed, { ...{"min":0,"max":16777215}, ...options }) }),
    inserted_at: fallbackFunctionTagger(({ seed, options }) => { return copycat.dateString(seed, { ...{"minYear":2020}, ...options }) }),
    updated_at: fallbackFunctionTagger(({ seed, options }) => { return copycat.dateString(seed, { ...{"minYear":2020}, ...options }) }),
    stripe_subscriptions: fallbackFunctionTagger(({ seed, options }) => { return ({ [copycat.word(seed)]: copycat.words(seed) }) }),
    stripe_invoices: fallbackFunctionTagger(({ seed, options }) => { return ({ [copycat.word(seed)]: copycat.words(seed) }) }),
    lifetime_plan?: fallbackFunctionTagger(({ seed, options }) => { return copycat.bool(seed) }),
    lifetime_plan_invoice: fallbackFunctionTagger(({ seed, options }) => { return copycat.sentence(seed, options).slice(0, 255) }),
    default_payment_method: fallbackFunctionTagger(({ seed, options }) => { return copycat.sentence(seed, options).slice(0, 255) }),
    custom_invoice_fields: fallbackFunctionTagger(({ seed, options }) => { return [({ [copycat.word(seed)]: copycat.words(seed) })] }),
    lifetime_plan: fallbackFunctionTagger(({ seed, options }) => { return copycat.bool(seed) })
  }
},

which results in an error when trying to run: node_modules/@snaplet/seed/dist/assets/userModels.js:52:17: ERROR: Expected "}" but found "?"

Silur commented 2 months ago

encountered the exact same issue, any update on this?

ronthedrummer commented 2 months ago

Also experiencing this. Trying to use Snaplet and I can't get it to work.

peterp commented 2 months ago

@mrjogo: You can try defining "lifetime_plan?" as a literal string, e.g.:

billing_accounts: {
  data: {
      'lifetime_plan?': "..."
  }
mrjogo commented 2 months ago

I didn't write that file, it was autogenerated.

woltsu commented 3 weeks ago

You can add the following property to seed.config.ts:

   ...
  select: ["!*", "public.*"],
   ...

Then, when you generate the seed, it will ignore all non-public tables.