Add sequential_id to calculate auto incrementing submission id

This commit is contained in:
bumi 2020-04-12 23:18:55 +02:00
parent 38166282a7
commit bffed7a606
5 changed files with 18 additions and 1 deletions

View File

@ -28,6 +28,7 @@ gem 'aws-sdk-s3', require: false
gem 'google-api-client'
gem 'rack-cors'
gem 'sentry-raven'
gem 'sequenced'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

View File

@ -197,6 +197,9 @@ GEM
semantic_range (2.3.0)
sentry-raven (3.0.0)
faraday (>= 1.0)
sequenced (3.2.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
signet (0.14.0)
addressable (~> 2.3)
faraday (>= 0.17.3, < 2.0)
@ -250,6 +253,7 @@ DEPENDENCIES
rails
sass-rails
sentry-raven
sequenced
spring
spring-watcher-listen
turbolinks

View File

@ -2,6 +2,8 @@ class Submission < ApplicationRecord
belongs_to :form
has_many_attached :files
acts_as_sequenced scope: :form_id
validates_presence_of :data, if: :appended_at?
def process_data(submitted_data)
@ -21,6 +23,10 @@ class Submission < ApplicationRecord
JSON.dump(value)
when 'tinyforms_now'
Time.now.utc.to_formatted_s(:rfc822)
when 'tinyforms_token'
form.token
when 'tinyforms_id'
sequential_id
when ActionDispatch::Http::UploadedFile
# 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

View File

@ -0,0 +1,5 @@
class AddSequentialIdToSubmissions < ActiveRecord::Migration[6.0]
def change
add_column :submissions, :sequential_id, :integer
end
end

View File

@ -10,7 +10,7 @@
#
# 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
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.string "remote_ip"
t.string "referrer"
t.integer "sequential_id"
end
create_table "users", force: :cascade do |t|