Logo-amall

hello guys, anybode know my seed stopped working?

Last active 11 days ago

16 replies

3 views

  • AN

    hello guys, anybode know my seed stopped working?

  • PK
    • Are you doing this in local dev?
    • Did you stop with nhost down and restart with nhost up?
    • I think it checks to see if DB and tables already exist and doesn't rerun if it finds them during startup. E.g. it only runs once, not every code changes/restart but could be wrong.
    • I wrapped my statements like so for good measure:
    DO $$ 
    DECLARE
        userid auth.users.id%TYPE = '12345678-1234-1234-1234-123456789012'; 
        otherid other.id%TYPE;
    BEGIN
        INSERT INTO auth.users (id, display_name, email, email_verified, locale, metadata)
         VALUES (userid, 'Fake Tester', 'test@nowhere.com', TRUE, 'en', '{"lastName":"Tester","firstName":"Fake"}')
          RETURNING id INTO userid;
        INSERT INTO other (col1, col2, col3) 
          VALUES ('Val1', 'Val2', 200)
          RETURNING id INTO otherid;
    END $$
    
  • AN

    -yes
    -yes
    -i cleaned my table before to try too, nothing

  • PK

    From https://github.com/nhost/nhost/blob/b2c1d900cfb2db8d69480c6d7aa8f09821ae7dbc/examples/seed-data/README.md

    "Seed data is only applied the first time when Nhost starts. If you want to re-apply seed data you need to delete the local database (rm -rf .nhost) and start Nhost again (nhost up)."

    I missed a step: need to delete the local dev DB before it'll run the seeds again.

  • PK

    Oooo. Or this shortcut if you'd rather leave everything else:

    "If seeds have been applied there will be a file seeds.applied within the .nhost/data//db directory.

    If you need to re-apply your seeds, delete this file and restart nhost."

  • PK

    From: https://github.com/nhost/nhost/blob/ffdcce1463dd25859b68491770742f82f7c7f5e1/docs/docs/cli/local-development.mdx#seed-data

  • PK

    This GH search probably gets you to the actual CLI code that does the seeds work if you need more info: https://github.com/nhost/cli/search?q=seeds

  • PK

    Note that git branches figure into this somehow too.

  • AN

    thanks @PK !

  • AN

    another quick solution can be use versions? like 0001therapistv1

  • AN

    like with migrations

  • AN

    i cant run again my migration on the cloud <:crythumbsup:943806398838489139>

  • PK

    Hmm. Interesting idea. Unsure.

  • PK

    This section of the CLI code suggests that won't make a difference. The seeds.applied file is a sentinel that stops all processing of the seeds directory whether or not there are new files that haven't been applied.

    https://github.com/nhost/cli/blob/c8fdacd2cbcf7c35f1224aa411e1d4cf117ee98a/nhost/service/manager.go#L309

  • PK

    What you're suggesting is more like the way migrations are done. Which you could also consider. For example, Hasura enums and any NHost enums that are stored in DB/PG would be a DB migration. If you need other data there permanently, perhaps it would be ok do create the data the same way.

  • PK

    Ask NHost support directly whether that's a good idea. Or create a new issue suggesting that seeds be expanded in their functionality. Or simply delete the file seeds.applied file and the entire seeds directory should get executed.

Last active 11 days ago

16 replies

3 views