CREATE ROLE yudao_flyway LOGIN NOINHERIT PASSWORD '123456';
CREATE ROLE yudao_runtime LOGIN NOINHERIT PASSWORD '123456';

ALTER SCHEMA public OWNER TO yudao_flyway;
DO $$
DECLARE
    object RECORD;
BEGIN
    FOR object IN
        SELECT format('%I.%I', schemaname, tablename) AS name
        FROM pg_tables
        WHERE schemaname = 'public'
    LOOP
        EXECUTE 'ALTER TABLE ' || object.name || ' OWNER TO yudao_flyway';
    END LOOP;
    FOR object IN
        SELECT format('%I.%I', sequence_schema, sequence_name) AS name
        FROM information_schema.sequences
        WHERE sequence_schema = 'public'
    LOOP
        EXECUTE 'ALTER SEQUENCE ' || object.name || ' OWNER TO yudao_flyway';
    END LOOP;
END
$$;
GRANT USAGE ON SCHEMA public TO yudao_runtime;
