added 260907 version of worker toolkit

This commit is contained in:
2026-09-08 20:30:51 -04:00
parent cbd3f0f8ca
commit 97aca37663
1283 changed files with 142951 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
class CreateExtensions < ActiveRecord::Migration[5.1]
def change
enable_extension "pg_trgm"
end
end

View File

@@ -0,0 +1,42 @@
class CreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|
## Database authenticatable
t.string :email, default: "", null: false
t.string :encrypted_password, default: "", null: false
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## API authentication token
t.string :authentication_token, null: false
## Invitable
t.string :invitation_token
t.datetime :invitation_created_at
t.datetime :invitation_sent_at
t.datetime :invitation_accepted_at
t.integer :invitation_limit
t.integer :invited_by_id
t.string :invited_by_type
t.timestamps null: false
end
add_index :users, :authentication_token, unique: true
add_index :users, :email, unique: true
add_index :users, :reset_password_token
add_index :users, :invitation_token, unique: true
end
end

View File

@@ -0,0 +1,13 @@
class CreateProfiles < ActiveRecord::Migration[5.1]
def change
create_table :profiles do |t|
t.belongs_to :user, index: true, foreign_key: true
t.string :country_id
t.date :birth_date
t.string :sex_id
t.string :onboarding_step_id
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateConditions < ActiveRecord::Migration[5.1]
def up
create_table :conditions do |t|
t.boolean :global, default: true
t.timestamps null: false
end
Condition.create_translation_table! name: :string
end
def down
drop_table :conditions
Condition.drop_translation_table!
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserConditions < ActiveRecord::Migration[5.1]
def change
create_table :user_conditions do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :condition, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,14 @@
class CreateSymptoms < ActiveRecord::Migration[5.1]
def up
create_table :symptoms do |t|
t.boolean :global, default: true
t.timestamps null: false
end
Symptom.create_translation_table! name: :string
end
def down
drop_table :symptoms
Symptom.drop_translation_table!
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserSymptoms < ActiveRecord::Migration[5.1]
def change
create_table :user_symptoms do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :symptom, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,17 @@
class CreateTrackings < ActiveRecord::Migration[5.1]
def change
create_table :trackings do |t|
t.belongs_to :user, index: true, foreign_key: true
t.references :trackable, polymorphic: true, index: true
t.date :start_at
t.date :end_at
t.integer :color_id
t.timestamps null: false
end
add_index :trackings, :trackable_type
add_index(:trackings,
[:user_id, :trackable_id, :trackable_type, :start_at],
unique: true, name: "index_trackings_unique_trackable")
end
end

View File

@@ -0,0 +1,14 @@
class CreateTreatments < ActiveRecord::Migration[5.1]
def up
create_table :treatments do |t|
t.boolean :global, default: true
t.timestamps null: false
end
Treatment.create_translation_table! name: :string
end
def down
drop_table :treatments
Treatment.drop_translation_table!
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserTreatments < ActiveRecord::Migration[5.1]
def change
create_table :user_treatments do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :treatment, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,13 @@
class CreateTags < ActiveRecord::Migration[5.1]
def up
create_table :tags do |t|
t.timestamps null: false
end
Tag.create_translation_table! name: :string
end
def down
drop_table :tags
Tag.drop_translation_table!
end
end

View File

@@ -0,0 +1,8 @@
class AddDemographicsToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :ethnicity_ids_string, :string
add_column :profiles, :day_habit_id, :string
add_column :profiles, :education_level_id, :string
add_column :profiles, :day_walking_hours, :integer
end
end

View File

@@ -0,0 +1,5 @@
class EnableHstoreExtension < ActiveRecord::Migration[5.1]
def change
enable_extension "hstore"
end
end

View File

@@ -0,0 +1,5 @@
class AddMostRecentDosesToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :most_recent_doses, :hstore
end
end

View File

@@ -0,0 +1,12 @@
class CreateTrackableUsages < ActiveRecord::Migration[5.1]
def change
create_table :trackable_usages do |t|
t.belongs_to :user, index: true, foreign_key: true
t.references :trackable, polymorphic: true, index: true
t.integer :count, default: 1
t.timestamps null: false
end
add_index :trackable_usages, [:user_id, :trackable_type, :trackable_id], unique: true, name: "index_trackable_usages_on_unique_columns"
end
end

View File

@@ -0,0 +1,7 @@
class AddTrackableUsagesCounts < ActiveRecord::Migration[5.1]
def change
add_column :conditions, :trackable_usages_count, :integer, default: 0
add_column :symptoms, :trackable_usages_count, :integer, default: 0
add_column :treatments, :trackable_usages_count, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class AddScreenNameToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :screen_name, :string
end
end

View File

@@ -0,0 +1,7 @@
class AddMostRecentPositionsToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :most_recent_conditions_positions, :hstore
add_column :profiles, :most_recent_symptoms_positions, :hstore
add_column :profiles, :most_recent_treatments_positions, :hstore
end
end

View File

@@ -0,0 +1,26 @@
class CreateFoods < ActiveRecord::Migration[5.1]
def change
create_table :foods do |t|
t.string :ndb_no
t.timestamps null: false
end
reversible do |dir|
dir.up do
Food.create_translation_table!(
long_desc: {type: :string, null: false},
shrt_desc: :string,
comname: :string,
sciname: :string
)
end
dir.down do
Food.drop_translation_table!
end
end
add_index :foods, :ndb_no
end
end

View File

@@ -0,0 +1,27 @@
class AddLongDescVectorIndexOnFoodTranslations < ActiveRecord::Migration[5.1]
disable_ddl_transaction!
def up
Food::LANG_MAP.each do |short_lang, long_lang|
drop_index(short_lang)
execute <<-SQL.strip_heredoc
CREATE INDEX CONCURRENTLY idx_fts_food_translations_#{short_lang} ON food_translations
USING gin(to_tsvector('#{long_lang}', long_desc))
WHERE locale = '#{short_lang}';
SQL
end
end
def down
Food::LANG_MAP.each do |short_lang, long_lang|
drop_index(short_lang)
end
end
private
def drop_index(short_lang)
execute "DROP INDEX CONCURRENTLY IF EXISTS idx_fts_food_translations_#{short_lang}"
end
end

View File

@@ -0,0 +1,19 @@
class CreateWeathers < ActiveRecord::Migration[5.1]
def change
create_table :weathers do |t|
t.date :date
t.string :postal_code
t.string :icon
t.string :summary
t.float :temperature_min
t.float :temperature_max
t.float :precip_intensity
t.float :pressure
t.float :humidity
t.timestamps null: false
end
add_index :weathers, %i[date postal_code], unique: true
end
end

View File

@@ -0,0 +1,6 @@
class AddPressureAndTemperatureSettingsToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :pressure_units, :integer, default: 0
add_column :profiles, :temperature_units, :integer, default: 0
end
end

View File

@@ -0,0 +1,5 @@
class AddBetaTesterToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :beta_tester, :boolean, default: false
end
end

View File

@@ -0,0 +1,16 @@
class CreateCronoJobs < ActiveRecord::Migration[5.1]
def self.up
create_table :crono_jobs do |t|
t.string :job_id, null: false
t.text :log, limit: 1073741823 # LONGTEXT for MySQL
t.datetime :last_performed_at
t.boolean :healthy
t.timestamps null: false
end
add_index :crono_jobs, [:job_id], unique: true
end
def self.down
drop_table :crono_jobs
end
end

View File

@@ -0,0 +1,5 @@
class AddNotifyToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :notify, :boolean, default: true
end
end

View File

@@ -0,0 +1,13 @@
class AddNotifyTokenToProfiles < ActiveRecord::Migration[5.1]
def up
add_column :profiles, :notify_token, :string
Profile.find_each(batch_size: 500) do |profile|
profile.send(:generate_notify_token)
profile.save
end
end
def down
remove_column :profiles, :notify_token
end
end

View File

@@ -0,0 +1,16 @@
class AddSlugNameToProfiles < ActiveRecord::Migration[5.1]
def up
add_column :profiles, :slug_name, :string
add_index :profiles, :slug_name
Profile.find_each(batch_size: 500) do |profile|
profile.send(:ensure_slug_name)
profile.save
end
end
def down
remove_column :profiles, :slug_name
remove_index :profiles, :slug_name
end
end

View File

@@ -0,0 +1,5 @@
class AddNotifyTopPostsToProfile < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :notify_top_posts, :boolean, default: true
end
end

View File

@@ -0,0 +1,6 @@
class AddGlobalToFoodsAndTags < ActiveRecord::Migration[5.1]
def change
add_column :foods, :global, :boolean, default: true
add_column :tags, :global, :boolean, default: true
end
end

View File

@@ -0,0 +1,5 @@
class AddTrackableUsageCountToTags < ActiveRecord::Migration[5.1]
def change
add_column :tags, :trackable_usages_count, :integer, default: 0
end
end

View File

@@ -0,0 +1,10 @@
class CreateUserTags < ActiveRecord::Migration[5.1]
def change
create_table :user_tags do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :tag, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,12 @@
class AddTrackableAbilityToFoods < ActiveRecord::Migration[5.1]
def change
add_column :foods, :trackable_usages_count, :integer, default: 0
create_table :user_foods do |t|
t.belongs_to :user, index: true, foreign_key: true
t.belongs_to :food, index: true, foreign_key: true
t.timestamps null: false
end
end
end

View File

@@ -0,0 +1,10 @@
class CreatePositions < ActiveRecord::Migration[5.1]
def change
create_table :positions do |t|
t.string :postal_code, null: false
t.string :location_name, null: false
t.decimal :latitude, {precision: 10, scale: 7}
t.decimal :longitude, {precision: 10, scale: 7}
end
end
end

View File

@@ -0,0 +1,5 @@
class AddPositionReferenceToWeather < ActiveRecord::Migration[5.1]
def change
add_reference :weathers, :position, foreign_key: true
end
end

View File

@@ -0,0 +1,8 @@
class AddCheckinReminderToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :checkin_reminder, :boolean, default: false
add_column :profiles, :checkin_reminder_at, :datetime
add_column :profiles, :time_zone_name, :string
add_column :profiles, :reminder_job_id, :string
end
end

View File

@@ -0,0 +1,5 @@
class AddRejectedTypeToProfiles < ActiveRecord::Migration[5.1]
def change
add_column :profiles, :rejected_type, :string
end
end