Add sequential_id to calculate auto incrementing submission id
This commit is contained in:
parent
38166282a7
commit
bffed7a606
1
Gemfile
1
Gemfile
|
@ -28,6 +28,7 @@ gem 'aws-sdk-s3', require: false
|
||||||
gem 'google-api-client'
|
gem 'google-api-client'
|
||||||
gem 'rack-cors'
|
gem 'rack-cors'
|
||||||
gem 'sentry-raven'
|
gem 'sentry-raven'
|
||||||
|
gem 'sequenced'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
|
|
|
@ -197,6 +197,9 @@ GEM
|
||||||
semantic_range (2.3.0)
|
semantic_range (2.3.0)
|
||||||
sentry-raven (3.0.0)
|
sentry-raven (3.0.0)
|
||||||
faraday (>= 1.0)
|
faraday (>= 1.0)
|
||||||
|
sequenced (3.2.0)
|
||||||
|
activerecord (>= 3.0)
|
||||||
|
activesupport (>= 3.0)
|
||||||
signet (0.14.0)
|
signet (0.14.0)
|
||||||
addressable (~> 2.3)
|
addressable (~> 2.3)
|
||||||
faraday (>= 0.17.3, < 2.0)
|
faraday (>= 0.17.3, < 2.0)
|
||||||
|
@ -250,6 +253,7 @@ DEPENDENCIES
|
||||||
rails
|
rails
|
||||||
sass-rails
|
sass-rails
|
||||||
sentry-raven
|
sentry-raven
|
||||||
|
sequenced
|
||||||
spring
|
spring
|
||||||
spring-watcher-listen
|
spring-watcher-listen
|
||||||
turbolinks
|
turbolinks
|
||||||
|
|
|
@ -2,6 +2,8 @@ class Submission < ApplicationRecord
|
||||||
belongs_to :form
|
belongs_to :form
|
||||||
has_many_attached :files
|
has_many_attached :files
|
||||||
|
|
||||||
|
acts_as_sequenced scope: :form_id
|
||||||
|
|
||||||
validates_presence_of :data, if: :appended_at?
|
validates_presence_of :data, if: :appended_at?
|
||||||
|
|
||||||
def process_data(submitted_data)
|
def process_data(submitted_data)
|
||||||
|
@ -21,6 +23,10 @@ class Submission < ApplicationRecord
|
||||||
JSON.dump(value)
|
JSON.dump(value)
|
||||||
when 'tinyforms_now'
|
when 'tinyforms_now'
|
||||||
Time.now.utc.to_formatted_s(:rfc822)
|
Time.now.utc.to_formatted_s(:rfc822)
|
||||||
|
when 'tinyforms_token'
|
||||||
|
form.token
|
||||||
|
when 'tinyforms_id'
|
||||||
|
sequential_id
|
||||||
when ActionDispatch::Http::UploadedFile
|
when ActionDispatch::Http::UploadedFile
|
||||||
# manually create the ActiveStorage attachment because we need the ID of the Attachment to create the URL
|
# manually create the ActiveStorage attachment because we need the ID of the Attachment to create the URL
|
||||||
# first the file needs to be uplaoded then we can create an Attachment
|
# first the file needs to be uplaoded then we can create an Attachment
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddSequentialIdToSubmissions < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :submissions, :sequential_id, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_04_09_001610) do
|
ActiveRecord::Schema.define(version: 2020_04_12_165834) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -63,6 +63,7 @@ ActiveRecord::Schema.define(version: 2020_04_09_001610) do
|
||||||
t.datetime "updated_at", precision: 6, null: false
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
t.string "remote_ip"
|
t.string "remote_ip"
|
||||||
t.string "referrer"
|
t.string "referrer"
|
||||||
|
t.integer "sequential_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: :cascade do |t|
|
create_table "users", force: :cascade do |t|
|
||||||
|
|
Loading…
Reference in New Issue