DO $$DECLARE
   this_version CONSTANT varchar := '00.01.021';
BEGIN
   PERFORM * FROM "DBVersion" WHERE version = this_version;
   IF FOUND THEN RETURN; END IF;


		INSERT INTO public."User" ("id", "name", "created_at","updated_at", "is_active")
		SELECT "id", "name", "created", "lastloggedin", CASE
					WHEN userstatus = 1
					THEN 0
					ELSE 1
			END
		FROM  public."UserInfo";

		--INSERT INTO public."UserContactInfo" ("id", "user", "created_at","ordinal", "type", "value")
		--SELECT  uuid_generate_v1(), "id", "created", 0, 0, "email"
		--FROM  public."UserInfo"
		--WHERE "email" is not null AND email != '';

		--INSERT INTO public."UserContactInfo" ("id", "user", "created_at", "ordinal", "type", "value")
		--SELECT  uuid_generate_v1(), "UserId", "CreationTime", 1, 0, "Email"
		--FROM  public."Credential"
		--WHERE "Email" is not null AND "Email" != '';

INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.021', '2023-11-20 12:00:00.000000+02', now(), 'Sync user tables data.');

END$$;