Remove namespaces.organization_id column default
Currently, namespaces.organization_id
has this defintion: organization_id bigint DEFAULT 1
.
We want this to be changed to: organization_id bigint NOT NULL
.
So we need to:
- Drop the default
- Make the column not null
The application code is already updated: everywhere we create a namespace
record, the organization id is explicitly set.
Implementation Plan
Since the table namespaces
is heavily used in the code base, we want to be extra careful and enable this change in steps, controlled by feature flags.
The DEFAULT 1
makes it hard to release this change: we can't easily add or remove the default 1
. So we temporarily move the responsibility of setting Default 1
from the database to the application (Namespace Model). We can then use the namespace_model_default_org
feature flag to control the roll out
We will use two Feature Flags:
MR | Rollout Issue | Feature Flag | Disabled | Enabled |
---|---|---|---|---|
!155732 (merged) | #470839 (closed) | require_organization |
Namespace models do not validate presence of Organization | Namespace models require an Organization |
!168228 (merged) | #492445 (closed) | namespace_model_default_org |
Namespace models do not set Default value | Namespace models set default value |
As part of the work in this issue, we first need to introduce the namespace_model_default_org
feature flag:
- Add a default value for the
organization_id
on theNamespace
model - This default value will only be set if the
namespace_model_default_org
is enabled.
Order of execution:
- Set organization_id to
DEFAULT 1 NOT NULL
. Make sure the columnnamespaces.organization_id
does not have NULL values before doing this) - Turn on
namespace_model_default_org
Feature Flag. - Set
organization_id
column toNOT NULL
(drop the DEFAULT) and remove thenamespace_model_default_org
- Turn on
require_organization
Feature flag. - Remove the
require_organization
Feature flag
References:
- Remove column defaults
- Changing column defaults (maybe not relevant?