-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make migrations work for Microsoft SQL Server
The activerecord-sqlserver-adapter gem sets IDENTITY for primary keys, and SQL Server disallows writing values into IDENTITY columns, which breaks most features in Rodauth that use tables where primary key is also a foreign key to the accounts table. IDENTITY columns are part of the SQL standard, and if the PostgreSQL adapter were to switch to IDENTITY columns for primary keys (like Sequel does), I believe it would have the same issue. The activerecord-sqlserver-adapter gem internally has mechanisms for temporarily allowing setting IDENTITY around insertion, but that's only activated when executing SQL queries via Active Record. We could call this API directly, but it's better to avoid IDENTITY columns altogether, like the Sequel migrations do. Creating the `id` column directly and passing `primary_key: true` as a secondary option appears to solve the issue, as it prevents the SQL Server adapter from setting the IDENTITY clause. The new migrations appear to produce the same or similar enough SQL on other adapters, so it should be a safe change. See #129
- Loading branch information
Showing
16 changed files
with
45 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/rodauth/migration/active_record/account_expiration.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
lib/generators/rodauth/migration/active_record/email_auth.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/rodauth/migration/active_record/password_expiration.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Used by the password expiration feature | ||
create_table :account_password_change_times<%= primary_key_type %> do |t| | ||
create_table :account_password_change_times, id: false do |t| | ||
t.<%= primary_key_type(nil) %> :id, primary_key: true | ||
t.foreign_key :accounts, column: :id | ||
t.datetime :changed_at, null: false, default: <%= current_timestamp %> | ||
end |
2 changes: 1 addition & 1 deletion
2
lib/generators/rodauth/migration/active_record/recovery_codes.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Used by the recovery codes feature | ||
create_table :account_recovery_codes, primary_key: [:id, :code] do |t| | ||
t.column :id, :<%= primary_key_type(nil) || :bigint %> | ||
t.<%= primary_key_type(nil) %> :id | ||
t.foreign_key :accounts, column: :id | ||
t.string :code | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/rodauth/migration/active_record/reset_password.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/rodauth/migration/active_record/single_session.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Used by the single session feature | ||
create_table :account_session_keys<%= primary_key_type %> do |t| | ||
create_table :account_session_keys, id: false do |t| | ||
t.<%= primary_key_type(nil) %> :id, primary_key: true | ||
t.foreign_key :accounts, column: :id | ||
t.string :key, null: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/rodauth/migration/active_record/verify_account.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/generators/rodauth/migration/active_record/verify_login_change.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters