nhost icon indicating copy to clipboard operation
nhost copied to clipboard

PostgresQL functions/triggers are not synced to local after init --remote

Open sangdth opened this issue 4 years ago • 1 comments

Steps to reproduce:

  • Create a new app on nhost dashboard.
  • Open Hasura, then:
    • Create a new table, for example, profiles with 2 UUID columns id and user_id.
    • Add function, create a trigger, for example in my case, I made a sync trigger:
CREATE OR REPLACE FUNCTION sync_user_profile() RETURNS TRIGGER AS
$BODY$
BEGIN
    INSERT INTO
        public.profiles(id, user_id)
        VALUES(new.id, new.id);

        RETURN new;
END;
$BODY$
language plpgsql;

CREATE TRIGGER trigger_sync
     AFTER INSERT ON auth.users
     FOR EACH ROW
     EXECUTE PROCEDURE sync_user_profile();
  • Test by inserting a user row, it works fine as a new profile row was created.
  • Init the project locally with nhost init --remote and select the recently created app.
  • The app running on local will have a profiles table, but the users table lost trigger.

sangdth avatar Jan 21 '22 15:01 sangdth

Currently I have to work around by creating the function locally again. But the trigger can not be migrated as trigger does not have CREATE OR REPLACE.

sangdth avatar Jan 21 '22 18:01 sangdth

This has been fixed in our CLI (https://github.com/nhost/cli/pull/324). Please upgrade the CLI (sudo nhost upgrade) and try again.

elitan avatar Oct 06 '22 06:10 elitan