Skip to content

Commit

Permalink
F2: Merge DB migrations (#550)
Browse files Browse the repository at this point in the history
* Merge migrations

* Remove model reference from migration

* Bump bundler version

* Dump schema

* Drop unused delayed jobs table
  • Loading branch information
dreikanter authored Jul 28, 2024
1 parent a44a266 commit 046136f
Show file tree
Hide file tree
Showing 38 changed files with 452 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN apt-get update --yes \
apt-utils \
build-essential \
vim \
&& gem install bundler:'~> 2.4' \
&& gem install bundler:'~> 2.5' \
&& rm -rf /var/lib/apt/lists/*

ARG RAILS_ENV
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20160912105557_create_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateFeeds < ActiveRecord::Migration[5.0]
def change
create_table :feeds do |t|
t.string :name, null: false
t.integer :posts_count, null: false, default: 0
t.datetime :refreshed_at

t.timestamps
end

add_index :feeds, :name, unique: true
end
end
17 changes: 17 additions & 0 deletions db/migrate/20160912110133_create_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreatePosts < ActiveRecord::Migration[5.0]
def change
create_table :posts do |t|
t.integer :feed_id, null: false
t.string :link, null: false
t.datetime :published_at, null: false
t.string :text, null: false, default: ""
t.string :attachments, null: false, array: true, default: []
t.string :comments, null: false, array: true, default: []
t.string :freefeed_post_id
t.timestamps
end

add_index :posts, :feed_id
add_index :posts, :link
end
end
22 changes: 22 additions & 0 deletions db/migrate/20160913121434_create_delayed_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CreateDelayedJobs < ActiveRecord::Migration[4.2]
def self.up
create_table :delayed_jobs, force: true do |table|
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
table.text :handler, null: false # YAML-encoded string of the object that will do work
table.text :last_error # reason for last failure (See Note below)
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
table.datetime :locked_at # Set when a client is working on this object
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
table.string :locked_by # Who is working on this object (if locked)
table.string :queue # The name of the queue this job is in
table.timestamps null: true
end

add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
end

def self.down
drop_table :delayed_jobs
end
end
11 changes: 11 additions & 0 deletions db/migrate/20160920171420_create_data_points.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateDataPoints < ActiveRecord::Migration[5.0]
def change
create_table :data_points do |t|
t.integer :series_id
t.json :details, null: false, default: {}
t.datetime :created_at, null: false
end

add_index :data_points, :series_id
end
end
10 changes: 10 additions & 0 deletions db/migrate/20160920171429_create_data_point_series.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateDataPointSeries < ActiveRecord::Migration[5.0]
def change
create_table :data_point_series do |t|
t.string :name, null: false
t.datetime :created_at, null: false
end

add_index :data_point_series, :name, unique: true
end
end
6 changes: 6 additions & 0 deletions db/migrate/20160926170407_add_post_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddPostStatus < ActiveRecord::Migration[5.0]
def change
add_column :posts, :status, :integer, null: false, default: 0
add_index :posts, :status
end
end
13 changes: 13 additions & 0 deletions db/migrate/20160926234238_update_post_statuses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class UpdatePostStatuses < ActiveRecord::Migration[5.0]
def up
# Replace "idle" status with "published"
execute <<-SQL
UPDATE posts
SET status = 2
WHERE status = 0 AND freefeed_post_id IS NOT NULL
SQL
end

def down
end
end
7 changes: 7 additions & 0 deletions db/migrate/20160929123932_add_feed_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddFeedDetails < ActiveRecord::Migration[5.0]
def change
add_column :feeds, :url, :string
add_column :feeds, :processor, :string
add_column :feeds, :normalizer, :string
end
end
17 changes: 17 additions & 0 deletions db/migrate/20170308200158_create_errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateErrors < ActiveRecord::Migration[5.0]
def change
create_table "errors" do |t|
t.integer "status", default: 0, null: false, index: true
t.string "error_class_name", default: "", null: false, index: true
t.string "file_name", index: true
t.integer "line_number"
t.string "label", default: "", null: false
t.string "message", default: "", null: false
t.string "backtrace", default: [], null: false, array: true
t.string "filtered_backtrace", default: [], null: false, array: true
t.json "context", default: {}, null: false
t.datetime "occured_at", null: false, index: true
t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180520150306_add_after_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAfterToFeeds < ActiveRecord::Migration[5.1]
def change
add_column :feeds, :after, :datetime
end
end
5 changes: 5 additions & 0 deletions db/migrate/20181029160355_add_refresh_time_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRefreshTimeToFeeds < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :refresh_interval, :integer, null: false, default: 0
end
end
5 changes: 5 additions & 0 deletions db/migrate/20181126110206_add_options_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOptionsToFeeds < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :options, :json, null: false, default: {}
end
end
5 changes: 5 additions & 0 deletions db/migrate/20181126152746_add_loader_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLoaderToFeeds < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :loader, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20181126170638_add_import_limit_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddImportLimitToFeeds < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :import_limit, :integer
end
end
10 changes: 10 additions & 0 deletions db/migrate/20181126194822_add_uid_to_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddUidToPosts < ActiveRecord::Migration[5.2]
class Post < ActiveRecord::Base
end

def change
add_column :posts, :uid, :string
Post.update_all("uid = link")
change_column :posts, :uid, :string, null: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLastPostCreatedAtToFeeds < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :last_post_created_at, :datetime
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190624150553_add_feed_subscriptions_count.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFeedSubscriptionsCount < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :subscriptions_count, :integer, null: false, default: 0
end
end
11 changes: 11 additions & 0 deletions db/migrate/20190701101346_create_blocked_ips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateBlockedIps < ActiveRecord::Migration[5.2]
def change
create_table :blocked_ips do |t|
t.inet :ip, null: false
t.datetime :created_at, default: -> { "CURRENT_TIMESTAMP" }
t.datetime :updated_at, default: -> { "CURRENT_TIMESTAMP" }
end

add_index :blocked_ips, :ip, unique: true
end
end
6 changes: 6 additions & 0 deletions db/migrate/20190726193542_add_feed_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddFeedStatus < ActiveRecord::Migration[5.2]
def change
add_column :feeds, :status, :integer, null: false, default: 0
add_index :feeds, :status
end
end
7 changes: 7 additions & 0 deletions db/migrate/20190817114629_add_target_to_errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddTargetToErrors < ActiveRecord::Migration[5.2]
def change
add_reference :errors, :target, polymorphic: true
remove_column :errors, :filtered_backtrace, :string, default: [], null: false, array: true
rename_column :errors, :error_class_name, :exception
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190819174940_default_occured_at.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DefaultOccuredAt < ActiveRecord::Migration[6.0]
def change
change_column :errors, :occured_at, :datetime, default: -> { "CURRENT_TIMESTAMP" }
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190822074055_add_validation_errors_to_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddValidationErrorsToPosts < ActiveRecord::Migration[6.0]
def change
add_column :posts, :validation_errors, :string, array: true, default: [], null: false
end
end
11 changes: 11 additions & 0 deletions db/migrate/20230604151916_create_nitter_instances.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateNitterInstances < ActiveRecord::Migration[6.1]
def change
create_table :nitter_instances do |t|
t.string :status, null: false, index: true
t.string :url, null: false, index: true
t.datetime :errored_at, index: true
t.integer :errors_count, null: false, default: 0
t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230607090837_add_state_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddStateToFeeds < ActiveRecord::Migration[6.1]
def change
add_column :feeds, :state, :string, null: false, default: "enabled"
end
end
6 changes: 6 additions & 0 deletions db/migrate/20230609145906_add_feed_error_counters.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddFeedErrorCounters < ActiveRecord::Migration[6.1]
def change
add_column :feeds, :errors_count, :integer, null: false, default: 0
add_column :feeds, :total_errors_count, :integer, null: false, default: 0
end
end
6 changes: 6 additions & 0 deletions db/migrate/20230613121056_change_feed_state_default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ChangeFeedStateDefault < ActiveRecord::Migration[6.1]
def change
add_column :feeds, :state_updated_at, :datetime
change_column_default :feeds, :state, from: "enabled", to: "pristine"
end
end
7 changes: 7 additions & 0 deletions db/migrate/20230615035946_add_disabling_reason_to_feeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddDisablingReasonToFeeds < ActiveRecord::Migration[6.1]
def change
add_column :feeds, :source, :string, null: false, default: ""
add_column :feeds, :description, :string, null: false, default: ""
add_column :feeds, :disabling_reason, :string, null: false, default: ""
end
end
9 changes: 9 additions & 0 deletions db/migrate/20230616143631_create_sparklines.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateSparklines < ActiveRecord::Migration[6.1]
def change
create_table :sparklines do |t|
t.belongs_to :feed, index: true
t.jsonb :data, null: false, default: {}
t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20230629142633_drop_blocked_ips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class DropBlockedIps < ActiveRecord::Migration[6.1]
def self.up
drop_table :blocked_ips
end

def self.down
create_table :blocked_ips do |t|
t.inet :ip, null: false
t.datetime :created_at, default: -> { "CURRENT_TIMESTAMP" }
t.datetime :updated_at, default: -> { "CURRENT_TIMESTAMP" }
end
end
end
19 changes: 19 additions & 0 deletions db/migrate/20230629170244_drop_data_points.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class DropDataPoints < ActiveRecord::Migration[6.1]
def self.up
drop_table :data_points
drop_table :data_point_series
end

def self.down
create_table :data_points do |t|
t.integer :series_id, index: true
t.json :details, null: false, default: {}
t.datetime :created_at, null: false
end

create_table :data_point_series do |t|
t.string :name, null: false, index: true
t.datetime :created_at, null: false
end
end
end
22 changes: 22 additions & 0 deletions db/migrate/20230630183347_add_state_to_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# State backfill:
#
# Status values:
# - idle: 0
# - ready: 1
# - published: 2
# - ignored: 3
# - not_valid: 4
# - error: 5
#
# scope = Post.where("created_at <= ?", DateTime.parse("Sat, 01 Jul 2023 14:15:16.356921000 UTC +00:00")); nil
# scope.where(status: 0).update_all(state: "rejected")
# scope.where(status: 2).update_all(state: "published")
# scope.where(status: 3).update_all(state: "rejected")
# scope.where(status: 4).update_all(state: "rejected")
# scope.where(status: 5).update_all(state: "failed")
#
class AddStateToPosts < ActiveRecord::Migration[6.1]
def change
add_column :posts, :state, :string, null: false, default: "draft"
end
end
16 changes: 16 additions & 0 deletions db/migrate/20230702113522_create_service_instances.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateServiceInstances < ActiveRecord::Migration[6.1]
def change
create_table :service_instances do |t|
t.string :service_type, null: false
t.string :state, null: false, index: true
t.string :url, null: false
t.integer :errors_count, null: false, default: 0
t.integer :total_errors_count, null: false, default: 0
t.datetime :used_at
t.datetime :failed_at
t.timestamps
end

add_index :service_instances, [:service_type, :url], unique: true
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddUsagesCountToServiceInstances < ActiveRecord::Migration[7.0]
def change
add_column :service_instances, :usages_count, :integer, null: false, default: 0
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230818131852_change_posts_link_default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangePostsLinkDefault < ActiveRecord::Migration[7.0]
def change
change_column_default :posts, :link, from: nil, to: ""
end
end
5 changes: 5 additions & 0 deletions db/migrate/20230818131932_add_posts_source_content.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPostsSourceContent < ActiveRecord::Migration[7.0]
def change
add_column :posts, :source_content, :jsonb, null: false, default: {}
end
end
22 changes: 22 additions & 0 deletions db/migrate/20240728141124_drop_delayed_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class DropDelayedJobs < ActiveRecord::Migration[7.1]
def up
drop_table :delayed_jobs, if_exists: true
end

def down
create_table :delayed_jobs, if_not_exists: true, force: true do |table|
table.integer :priority, default: 0, null: false
table.integer :attempts, default: 0, null: false
table.text :handler, null: false
table.text :last_error
table.datetime :run_at
table.datetime :locked_at
table.datetime :failed_at
table.string :locked_by
table.string :queue
table.timestamps null: true
end

add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
end
end
Loading

0 comments on commit 046136f

Please sign in to comment.