Skip to content

Commit

Permalink
Enable RLS (Row Level Security)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitzanpap committed Aug 13, 2024
1 parent 2828075 commit d977fb2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server/internal/configs/dbConfigs/db.config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func ConnectToDBPool(dbURL string) (*pgxpool.Pool, error) {

func InitDB(db *pgx.Conn) {
createDbTables(db)
enableRLS(db)
createPreparedStatements(db)
}

Expand Down Expand Up @@ -81,6 +82,20 @@ func createDbTables(db *pgx.Conn) {
}
}

func enableRLS(db *pgx.Conn) {
// Enable RLS on the Users table
_, err := db.Exec(context.Background(), "ALTER TABLE users ENABLE ROW LEVEL SECURITY;")
if err != nil {
log.Fatalf(colors.Error("Unable to enable RLS on users table: %v\n"), err)
}

// Enable RLS on the URLs table
_, err = db.Exec(context.Background(), "ALTER TABLE urls ENABLE ROW LEVEL SECURITY;")
if err != nil {
log.Fatalf(colors.Error("Unable to enable RLS on urls table: %v\n"), err)
}
}

var PreparedStatements = preparedStatementsStruct{
CreateUserRow: "createUserRow",
GetUserRow: "getUserRow",
Expand Down

0 comments on commit d977fb2

Please sign in to comment.