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
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Most of the application logic lives in the **CoPlan Rails engine** (`engine/`),
- Enums are stored as **strings** (not integers) — validated with constants and `inclusion:` validators
- JSON columns for arrays/hashes (`tags`, `metadata`, `trigger_statuses`, `allowed_email_domains`)
- No PG-only types (`citext`, `text[]`, `ON CONFLICT ... WHERE`) — use Rails validations and `json` columns
- **No foreign key constraints** — the ODS/Aurora `app` DB user lacks `REFERENCES` privilege. Use indexes on relationship columns instead of `add_foreign_key`. Referential integrity is enforced at the application layer via validations.
- `Current.organization` and `Current.user` are set per-request for scoping

## Model Conventions
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/coplan.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
CoPlan.configure do |config|
config.sign_in_path = "/sign_in"

config.authenticate = ->(request) {
user_id = request.session[:user_id]
return nil unless user_id
Expand Down
6 changes: 5 additions & 1 deletion engine/app/controllers/coplan/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def authenticate_coplan_user!

attrs = callback.call(request)
unless attrs && attrs[:external_id].present?
head :unauthorized
if CoPlan.configuration.sign_in_path
redirect_to CoPlan.configuration.sign_in_path, alert: "Please sign in."
else
head :unauthorized
end
return
end

Expand Down
26 changes: 7 additions & 19 deletions engine/db/migrate/20260226200000_create_coplan_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def change
add_index :coplan_plans, :status
add_index :coplan_plans, :updated_at
add_index :coplan_plans, :created_by_user_id
add_foreign_key :coplan_plans, :coplan_users, column: :created_by_user_id

Comment on lines 28 to 29

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Sync installed migration copy with FK removal

This commit removes add_foreign_key calls only in engine/db/migrate/20260226200000_create_coplan_schema.rb, but the repository still contains the installed migration copy at db/migrate/20260226200000_create_coplan_schema.co_plan.rb with all of the original FK statements (for example at lines 29, 52, 69, etc.). In environments that run the copied app migration (which is exactly the case once coplan:install:migrations has been used, and this repo already has that copy), db:migrate will still execute FK DDL and hit the same REFERENCES-privilege failure, so the migration fix is effectively not applied.

Useful? React with 👍 / 👎.

create_table :coplan_plan_versions, id: { type: :string, limit: 36 } do |t|
t.string :plan_id, limit: 36, null: false
Expand All @@ -49,10 +48,7 @@ def change
add_index :coplan_plan_versions, :plan_id
add_index :coplan_plan_versions, [:plan_id, :revision], unique: true
add_index :coplan_plan_versions, [:plan_id, :created_at]
add_foreign_key :coplan_plan_versions, :coplan_plans, column: :plan_id

# Now that coplan_plan_versions exists, add the FK for current_plan_version_id
add_foreign_key :coplan_plans, :coplan_plan_versions, column: :current_plan_version_id
add_index :coplan_plans, :current_plan_version_id

create_table :coplan_plan_collaborators, id: { type: :string, limit: 36 } do |t|
t.string :plan_id, limit: 36, null: false
Expand All @@ -66,9 +62,6 @@ def change
add_index :coplan_plan_collaborators, :user_id
add_index :coplan_plan_collaborators, :added_by_user_id
add_index :coplan_plan_collaborators, [:plan_id, :user_id], unique: true
add_foreign_key :coplan_plan_collaborators, :coplan_plans, column: :plan_id
add_foreign_key :coplan_plan_collaborators, :coplan_users, column: :user_id
add_foreign_key :coplan_plan_collaborators, :coplan_users, column: :added_by_user_id

create_table :coplan_comment_threads, id: { type: :string, limit: 36 } do |t|
t.string :plan_id, limit: 36, null: false
Expand All @@ -91,12 +84,11 @@ def change

add_index :coplan_comment_threads, [:plan_id, :status]
add_index :coplan_comment_threads, [:plan_id, :out_of_date]
add_foreign_key :coplan_comment_threads, :coplan_plans, column: :plan_id
add_foreign_key :coplan_comment_threads, :coplan_plan_versions, column: :plan_version_id
add_foreign_key :coplan_comment_threads, :coplan_plan_versions, column: :addressed_in_plan_version_id
add_foreign_key :coplan_comment_threads, :coplan_plan_versions, column: :out_of_date_since_version_id
add_foreign_key :coplan_comment_threads, :coplan_users, column: :created_by_user_id
add_foreign_key :coplan_comment_threads, :coplan_users, column: :resolved_by_user_id
add_index :coplan_comment_threads, :plan_version_id
add_index :coplan_comment_threads, :created_by_user_id
add_index :coplan_comment_threads, :resolved_by_user_id
add_index :coplan_comment_threads, :addressed_in_plan_version_id
add_index :coplan_comment_threads, :out_of_date_since_version_id

create_table :coplan_comments, id: { type: :string, limit: 36 } do |t|
t.string :comment_thread_id, limit: 36, null: false
Expand All @@ -108,7 +100,6 @@ def change
end

add_index :coplan_comments, [:comment_thread_id, :created_at]
add_foreign_key :coplan_comments, :coplan_comment_threads, column: :comment_thread_id

create_table :coplan_edit_leases, id: { type: :string, limit: 36 } do |t|
t.string :plan_id, limit: 36, null: false
Expand All @@ -121,7 +112,6 @@ def change
end

add_index :coplan_edit_leases, :plan_id, unique: true
add_foreign_key :coplan_edit_leases, :coplan_plans, column: :plan_id

create_table :coplan_edit_sessions, id: { type: :string, limit: 36 } do |t|
t.string :plan_id, limit: 36, null: false
Expand All @@ -139,8 +129,7 @@ def change
end

add_index :coplan_edit_sessions, [:plan_id, :status]
add_foreign_key :coplan_edit_sessions, :coplan_plans, column: :plan_id
add_foreign_key :coplan_edit_sessions, :coplan_plan_versions, column: :plan_version_id
add_index :coplan_edit_sessions, :plan_version_id

create_table :coplan_api_tokens, id: { type: :string, limit: 36 } do |t|
t.string :user_id, limit: 36, null: false
Expand All @@ -155,7 +144,6 @@ def change

add_index :coplan_api_tokens, :user_id
add_index :coplan_api_tokens, :token_digest, unique: true
add_foreign_key :coplan_api_tokens, :coplan_users, column: :user_id

create_table :coplan_automated_plan_reviewers, id: { type: :string, limit: 36 } do |t|
t.string :key, null: false
Expand Down
2 changes: 1 addition & 1 deletion engine/lib/coplan/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CoPlan
class Configuration
attr_accessor :authenticate
attr_accessor :authenticate, :sign_in_path
attr_accessor :ai_base_url, :ai_api_key, :ai_model
attr_accessor :error_reporter
attr_accessor :notification_handler
Expand Down