fix(db): resolve pg role issues
- Seperate posgres user for development and testing
This commit is contained in:
		@@ -21,7 +21,8 @@ def migrate() -> None:
 | 
			
		||||
    port = url_parts.port
 | 
			
		||||
 | 
			
		||||
    print(
 | 
			
		||||
        f"The database name is {dbname}, the username is {user_name}, the password is {password}, the host is {host}, the port is {port}"
 | 
			
		||||
        f"The database name is {dbname}, the username is {user_name}, "
 | 
			
		||||
        f"the password is {password}, the host is {host}, the port is {port}"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    with psycopg.connect(
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,9 @@ def recreate_db() -> None:
 | 
			
		||||
    port = url_parts.port
 | 
			
		||||
 | 
			
		||||
    print(
 | 
			
		||||
        f"The database name is {dbname}, the username is {user_name}, the password is {password}, the host is {host}, the port is {port}"
 | 
			
		||||
        "Running database recreation script, "
 | 
			
		||||
        f"The database name is {dbname}, the username is {user_name}, "
 | 
			
		||||
        f"the password is {password}, the host is {host}, the port is {port}"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    with psycopg.connect(
 | 
			
		||||
@@ -31,8 +33,17 @@ def recreate_db() -> None:
 | 
			
		||||
            conn._set_autocommit(True)
 | 
			
		||||
 | 
			
		||||
            cur.execute(
 | 
			
		||||
                sql.SQL("DROP OWNED BY {}").format(
 | 
			
		||||
                    sql.Identifier(user_name)  # type: ignore
 | 
			
		||||
                sql.SQL(
 | 
			
		||||
                    """
 | 
			
		||||
                    DO $$
 | 
			
		||||
                    BEGIN
 | 
			
		||||
                        IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = '{}') THEN
 | 
			
		||||
                            DROP OWNED BY {};
 | 
			
		||||
                        END IF;
 | 
			
		||||
                    END $$;
 | 
			
		||||
                    """
 | 
			
		||||
                ).format(
 | 
			
		||||
                    sql.Identifier(user_name), sql.Identifier(user_name)  # type: ignore
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +53,7 @@ def recreate_db() -> None:
 | 
			
		||||
                    dbname=sql.Identifier(dbname),
 | 
			
		||||
                )
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            # Drop the user if it exists
 | 
			
		||||
            cur.execute(
 | 
			
		||||
                sql.SQL("DROP USER IF EXISTS {}").format(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user