Skip to content

Commit

Permalink
Update timestamp defaults to CURRENT_TIMESTAMP
Browse files Browse the repository at this point in the history
Changed default value for `created_at` and `updated_at` columns to `CURRENT_TIMESTAMP` for consistency and standardization. This ensures database entries have automatic timestamping based on the current time. Additionally, improved handling of default values in SQL generation to accommodate new logic.
  • Loading branch information
eliasjpr committed Aug 20, 2024
1 parent 9d7a385 commit 43cca92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/expression/generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,11 @@ module Expression
else
sb << column.name
sb << " " << @adapter.sql_type(column.type)
sb << " DEFAULT CURRENT_TIMESTAMP " if [:created_at, :updated_at].includes?(column.name)
if [:created_at, :updated_at].includes?(column.name)
sb << " DEFAULT " << column.default
elsif column.default
sb << " DEFAULT " << column.default
end
sb << " NOT NULL" unless column.null?
sb << " UNIQUE" if column.unique?
end
Expand Down
4 changes: 2 additions & 2 deletions src/table.cr
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ module Cql
# timestamps
# ```
def timestamps
timestamp :created_at, default: Time.local
timestamp :updated_at, default: Time.local
timestamp :created_at, default: "CURRENT_TIMESTAMP"
timestamp :updated_at, default: "CURRENT_TIMESTAMP"
end

# Adds a new column to the table.
Expand Down

0 comments on commit 43cca92

Please sign in to comment.