Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: change schema object owner (#16853)
Danny Xufe1e29923f00
diff --git a/backend/migrator/migration/3.8/0003##change_table_ownership_to_current_user.sql b/backend/migrator/migration/3.8/0003##change_table_ownership_to_current_user.sqlnew file mode 100644index 0000000000..266f51c157--- /dev/null+++ b/backend/migrator/migration/3.8/0003##change_table_ownership_to_current_user.sql@@ -0,0 +1,27 @@+-- Change ownership of all Bytebase tables and sequences to the current connection user+DO $$+DECLARE+ current_user_name text;+ obj_rec RECORD;+BEGIN+ -- Get current user+ current_user_name := current_user;++ -- Change ownership for all tables in current schema+ FOR obj_rec IN+ SELECT tablename+ FROM pg_tables+ WHERE schemaname = current_schema+ LOOP+ EXECUTE format('ALTER TABLE %I OWNER TO %I', obj_rec.tablename, current_user_name);+ END LOOP;++ -- Change ownership for all sequences in current schema+ FOR obj_rec IN+ SELECT sequence_name+ FROM information_schema.sequences+ WHERE sequence_schema = current_schema+ LOOP+ EXECUTE format('ALTER SEQUENCE %I OWNER TO %I', obj_rec.sequence_name, current_user_name);+ END LOOP;+END $$;\ No newline at end of filediff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.goindex d12af7786c..80e1cf0a4d 100644--- a/backend/migrator/migrator_test.go+++ b/backend/migrator/migrator_test.go@@ -12,7 +12,7 @@ import (func TestLatestVersion(t *testing.T) {files, err := getSortedVersionedFiles()require.NoError(t, err)- require.Equal(t, semver.MustParse("3.8.2"), *files[len(files)-1].version)+ require.Equal(t, semver.MustParse("3.8.3"), *files[len(files)-1].version)}func TestVersionUnique(t *testing.T) {