Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rev_group_rule_cci_map should include a foreign key constraint #1418

Open
csmig opened this issue Oct 23, 2024 · 0 comments
Open

rev_group_rule_cci_map should include a foreign key constraint #1418

csmig opened this issue Oct 23, 2024 · 0 comments
Labels

Comments

@csmig
Copy link
Member

csmig commented Oct 23, 2024

rev_group_rule_cci_map maps CCIs to rows in rev_group_rule_map using the field rgrId.

However, there is no foreign key constraint or CASCADE behavior defined. Therefore, when a STIG revision is removed and the records in rev_group_rule_map are cascade deleted, the rows in rev_group_rule_cci_map remain. This will create unnecessary bloat over time.

Suggested migration:

const MigrationHandler = require('./lib/MigrationHandler')

const upMigration = [
  `DELETE rgrcc FROM rev_group_rule_cci_map rgrcc left join rev_group_rule_map rgr using (rgrId) 
  where rgr.rgrId is null`,
  `ALTER TABLE rev_group_rule_cci_map ADD CONSTRAINT fk_rev_group_rule_cci_map_1 
  FOREIGN KEY (rgrId) REFERENCES rev_group_rule_map (rgrId) ON DELETE CASCADE ON UPDATE CASCADE`
]

const downMigration = [
]

const migrationHandler = new MigrationHandler(upMigration, downMigration)
module.exports = {
  up: async (pool) => {
    await migrationHandler.up(pool, __filename)
  },
  down: async (pool) => {
    await migrationHandler.down(pool, __filename)
  }
}
@csmig csmig added the DB label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant