Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions db/migrate/20260608090600_create_systems.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CreateSystems < ActiveRecord::Migration[7.1]
def change
create_table :systems, id: :uuid do |t|
t.string :account, limit: 10
t.string :org_id, limit: 10, null: false
t.string :display_name, limit: 200, null: false
t.jsonb :tags, null: false, default: {}
t.datetime :updated, null: false
t.datetime :created, null: false
Comment thread
romanblanco marked this conversation as resolved.
t.datetime :stale_timestamp, null: false
t.jsonb :system_profile, null: false, default: {}
t.jsonb :groups, default: []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Add null: false constraint to groups for consistency.

The groups field allows NULL values, unlike the other JSONB fields (tags and system_profile) which have null: false constraints. This inconsistency could lead to unexpected behavior when querying or processing group data.

🛡️ Proposed fix to add null constraint
-      t.jsonb :groups, default: []
+      t.jsonb :groups, null: false, default: []
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
t.jsonb :groups, default: []
t.jsonb :groups, null: false, default: []
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@db/migrate/20260601090600_create_systems.rb` at line 12, Update the migration
definition for the groups JSONB column to prevent NULLs: change the column
declaration "t.jsonb :groups, default: []" to include "null: false" (i.e.
"t.jsonb :groups, default: [], null: false") in the CreateSystems migration (the
line with t.jsonb :groups) so the groups field has the same non-null constraint
as tags and system_profile; if this migration has already run in environments,
instead add a separate migration that sets existing NULL groups to [] and then
alters the column to set NOT NULL on the systems table.

t.uuid :insights_id
t.datetime :deleted_at
end

add_index :systems, :insights_id, unique: true
end
end
17 changes: 16 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_05_28_153533) do
ActiveRecord::Schema[8.1].define(version: 2026_06_08_090600) do
# These are extensions that must be enabled in order to support this database
enable_extension "dblink"
enable_extension "pgcrypto"
Expand Down Expand Up @@ -281,6 +281,21 @@
t.index ["ref_id", "version"], name: "index_security_guides_v2_on_ref_id_and_version", unique: true
end

create_table "systems", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "account", limit: 10
t.datetime "created", null: false
t.datetime "deleted_at"
t.string "display_name", limit: 200, null: false
t.jsonb "groups", default: []
t.uuid "insights_id"
t.string "org_id", limit: 10, null: false
t.datetime "stale_timestamp", null: false
t.jsonb "system_profile", default: {}, null: false
t.jsonb "tags", default: {}, null: false
t.datetime "updated", null: false
t.index ["insights_id"], name: "index_systems_on_insights_id", unique: true
end

create_table "tailoring_rules_v2", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", precision: nil
t.uuid "rule_id", null: false
Expand Down
Loading