forked from e621ng/e621ng
Replace post archive service with inline code
This commit is contained in:
parent
2f5964292b
commit
5d8494caac
@ -1,6 +1,5 @@
|
||||
class PostVersionsController < ApplicationController
|
||||
before_action :member_only
|
||||
before_action :check_availabililty
|
||||
respond_to :html, :xml, :json
|
||||
|
||||
def index
|
||||
@ -26,12 +25,4 @@ class PostVersionsController < ApplicationController
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_availabililty
|
||||
if !PostArchive.enabled?
|
||||
raise NotImplementedError.new("Archive service is not configured. Post versions are not saved.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,8 +3,6 @@ module Moderator
|
||||
module Queries
|
||||
class Tag < ::Struct.new(:user, :count)
|
||||
def self.all(min_date, max_level)
|
||||
return [] unless PostArchive.enabled?
|
||||
|
||||
records = PostArchive.where("updated_at > ?", min_date).group(:updater).count.map do |user, count|
|
||||
new(user, count)
|
||||
end
|
||||
|
@ -34,8 +34,8 @@ module Moderator
|
||||
add_row(sums, UserFeedback.where(creator_ip_addr: ip_addrs).group(:creator).count)
|
||||
add_row(sums, Hash[User.where(last_ip_addr: ip_addrs).collect { |user| [user, 1] }])
|
||||
|
||||
add_row_id(sums, PoolArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PoolArchive.enabled?
|
||||
add_row_id(sums, PostArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count) if PostArchive.enabled?
|
||||
add_row_id(sums, PoolArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count)
|
||||
add_row_id(sums, PostArchive.where(updater_ip_addr: ip_addrs).group(:updater_id).count)
|
||||
|
||||
sums
|
||||
end
|
||||
@ -52,8 +52,8 @@ module Moderator
|
||||
add_row(sums, ArtistCommentaryVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, ArtistVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, NoteVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, PoolArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PoolArchive.enabled?
|
||||
add_row(sums, PostArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count) if PostArchive.enabled?
|
||||
add_row(sums, PoolArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count)
|
||||
add_row(sums, PostArchive.where(updater_id: users.map(&:id)).group(:updater_ip_addr).count)
|
||||
add_row(sums, WikiPageVersion.where(updater: users).group(:updater_ip_addr).count)
|
||||
add_row(sums, Comment.where(creator: users).group(:creator_ip_addr).count)
|
||||
add_row(sums, Dmail.where(from: users).group(:creator_ip_addr).count)
|
||||
|
@ -28,7 +28,7 @@ class RelatedTagQuery
|
||||
|
||||
# Returns the top 20 most frequently added tags within the last 20 edits made by the user in the last hour.
|
||||
def recent_tags(since: 1.hour.ago, max_edits: 20, max_tags: 20)
|
||||
return [] unless user.present? && PostArchive.enabled?
|
||||
return [] unless user.present?
|
||||
|
||||
versions = PostArchive.where(updater_id: user.id).where("updated_at > ?", since).order(id: :desc).limit(max_edits)
|
||||
tags = versions.flat_map(&:added_tags)
|
||||
|
@ -1,122 +0,0 @@
|
||||
class PoolVersion < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
|
||||
belongs_to :pool
|
||||
belongs_to_updater
|
||||
|
||||
module SearchMethods
|
||||
def for_user(user_id)
|
||||
where("updater_id = ?", user_id)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
if params[:updater_id].present?
|
||||
q = q.for_user(params[:updater_id].to_i)
|
||||
end
|
||||
|
||||
if params[:updater_name].present?
|
||||
q = q.where("updater_id = (select _.id from users _ where lower(_.name) = ?)", params[:updater_name].mb_chars.downcase)
|
||||
end
|
||||
|
||||
if params[:pool_id].present?
|
||||
q = q.where("pool_id = ?", params[:pool_id].to_i)
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
|
||||
def self.export_to_archives(starting_version_id = 0)
|
||||
raise NotImplementedError.new("SQS URL not setup") if Danbooru.config.aws_sqs_archives_url.nil?
|
||||
|
||||
credentials = Aws::Credentials.new(
|
||||
Danbooru.config.aws_access_key_id,
|
||||
Danbooru.config.aws_secret_access_key
|
||||
)
|
||||
sqs = Aws::SQS::Client.new(
|
||||
credentials: credentials,
|
||||
region: Danbooru.config.aws_sqs_region
|
||||
)
|
||||
last_version_id = 0
|
||||
|
||||
where("id > ?", starting_version_id).find_each do |version|
|
||||
last_version_id = version.id
|
||||
|
||||
json = {
|
||||
id: version.id,
|
||||
pool_id: version.pool_id,
|
||||
post_ids: version.post_ids.scan(/\d+/).map(&:to_i),
|
||||
updater_id: version.updater_id,
|
||||
updater_ip_addr: version.updater_ip_addr.to_s,
|
||||
created_at: version.created_at.try(:iso8601),
|
||||
updated_at: version.updated_at.try(:iso8601),
|
||||
description: version.pool.description,
|
||||
name: version.name,
|
||||
is_active: version.pool.is_active?,
|
||||
is_deleted: version.pool.is_deleted?,
|
||||
category: version.pool.category
|
||||
}
|
||||
msg = "add pool version\n#{json.to_json}"
|
||||
sqs.send_message(
|
||||
message_body: msg,
|
||||
queue_url: Danbooru.config.aws_sqs_archives_url
|
||||
)
|
||||
end
|
||||
|
||||
puts "last version id: #{last_version_id}"
|
||||
end
|
||||
|
||||
def pretty_name
|
||||
name.tr("_", " ")
|
||||
end
|
||||
|
||||
def post_id_array
|
||||
@post_id_array ||= post_ids.scan(/\d+/).map(&:to_i)
|
||||
end
|
||||
|
||||
def diff(version)
|
||||
new_posts = post_id_array
|
||||
old_posts = version.present? ? version.post_id_array : []
|
||||
|
||||
return {
|
||||
:added_posts => array_difference_with_duplicates(new_posts, old_posts),
|
||||
:removed_posts => array_difference_with_duplicates(old_posts, new_posts),
|
||||
:unchanged_posts => array_intersect_with_duplicates(new_posts, old_posts)
|
||||
}
|
||||
end
|
||||
|
||||
def array_difference_with_duplicates(array, other_array)
|
||||
new_array = array.dup
|
||||
other_array.each do |id|
|
||||
index = new_array.index(id)
|
||||
if index
|
||||
new_array.delete_at(index)
|
||||
end
|
||||
end
|
||||
new_array
|
||||
end
|
||||
|
||||
def array_intersect_with_duplicates(array, other_array)
|
||||
other_array = other_array.dup
|
||||
array.inject([]) do |intersect, id|
|
||||
index = other_array.index(id)
|
||||
if index
|
||||
intersect << id
|
||||
other_array.delete_at(index)
|
||||
end
|
||||
intersect
|
||||
end
|
||||
end
|
||||
|
||||
def changes
|
||||
@changes ||= diff(previous)
|
||||
end
|
||||
|
||||
def previous
|
||||
PoolArchive.where(["pool_id = ? and updated_at < ?", pool_id, updated_at]).order("updated_at desc").first
|
||||
end
|
||||
end
|
@ -61,9 +61,7 @@ class Post < ApplicationRecord
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning, :view_count
|
||||
|
||||
if PostArchive.enabled?
|
||||
has_many :versions, -> {Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC")}, :class_name => "PostArchive", :dependent => :destroy
|
||||
end
|
||||
has_many :versions, -> {Rails.env.test? ? order("post_versions.updated_at ASC, post_versions.id ASC") : order("post_versions.updated_at ASC")}, :class_name => "PostArchive", :dependent => :destroy
|
||||
|
||||
module FileMethods
|
||||
extend ActiveSupport::Concern
|
||||
@ -1444,7 +1442,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def saved_change_to_watched_attributes?
|
||||
saved_change_to_rating? || saved_change_to_source? || saved_change_to_parent_id? || saved_change_to_tag_string?
|
||||
saved_change_to_rating? || saved_change_to_source? || saved_change_to_parent_id? || saved_change_to_tag_string? || saved_change_to_locked_tags?
|
||||
end
|
||||
|
||||
def merge_version?
|
||||
@ -1454,7 +1452,7 @@ class Post < ApplicationRecord
|
||||
|
||||
def create_new_version
|
||||
User.where(id: CurrentUser.id).update_all("post_update_count = post_update_count + 1")
|
||||
PostArchive.queue(self) if PostArchive.enabled?
|
||||
PostArchive.create_from_post(self)
|
||||
end
|
||||
|
||||
def revert_to(target)
|
||||
|
@ -4,11 +4,10 @@ class PostArchive < ApplicationRecord
|
||||
belongs_to :post
|
||||
belongs_to_updater counter_cache: "post_update_count"
|
||||
|
||||
def self.enabled?
|
||||
Rails.env.test? || Danbooru.config.post_archive_enabled?
|
||||
end
|
||||
before_validation :fill_version, on: :create
|
||||
before_validation :fill_changes, on: :create
|
||||
|
||||
establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled?
|
||||
#establish_connection (ENV["ARCHIVE_DATABASE_URL"] || "archive_#{Rails.env}".to_sym) if enabled?
|
||||
self.table_name = "post_versions"
|
||||
|
||||
def self.check_for_retry(msg)
|
||||
@ -54,35 +53,61 @@ class PostArchive < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ArchiveServiceMethods
|
||||
extend ActiveSupport::Concern
|
||||
extend SearchMethods
|
||||
|
||||
class_methods do
|
||||
def queue(post)
|
||||
raise NotImplementedError.new("Archive service is not configured") if !enabled?
|
||||
json_post = {
|
||||
"post_id" => post.id,
|
||||
"rating" => post.rating,
|
||||
"parent_id" => post.parent_id,
|
||||
"source" => post.source,
|
||||
"updater_id" => CurrentUser.id,
|
||||
"updater_ip_addr" => CurrentUser.ip_addr.to_s,
|
||||
"updated_at" => post.updated_at.try(:iso8601),
|
||||
"created_at" => post.created_at.try(:iso8601),
|
||||
"tags" => post.tag_string
|
||||
}
|
||||
AddPostVersionJob.perform_async(post.id, json_post)
|
||||
end
|
||||
end
|
||||
def self.create_from_post(post)
|
||||
self.create({
|
||||
post_id: post.id,
|
||||
rating: post.rating,
|
||||
parent_id: post.parent_id,
|
||||
source: post.source,
|
||||
updater_id: CurrentUser.id,
|
||||
updater_ip_addr: CurrentUser.ip_addr,
|
||||
tags: post.tag_string,
|
||||
locked_tags: post.locked_tags
|
||||
})
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ArchiveServiceMethods
|
||||
def self.find_previous(post_id, updated_at)
|
||||
where("post_id = ? and updated_at < ?", post_id, updated_at).order("id desc").first
|
||||
end
|
||||
|
||||
def self.calculate_version(post_id)
|
||||
1 + where("post_id = ?", post_id).maximum(:version).to_i
|
||||
end
|
||||
|
||||
def fill_version
|
||||
self.version = PostArchive.calculate_version (self.post_id)
|
||||
end
|
||||
|
||||
def fill_changes
|
||||
prev = previous
|
||||
|
||||
if prev
|
||||
self.added_tags = tag_array - prev.tag_array
|
||||
self.removed_tags = prev.tag_array - tag_array
|
||||
self.added_locked_tags = locked_tag_array - prev.locked_tag_array
|
||||
self.removed_locked_tags = prev.locked_tag_array - locked_tag_array
|
||||
else
|
||||
self.added_tags = tag_array
|
||||
self.removed_tags = []
|
||||
self.added_locked_tags = locked_tag_array
|
||||
self.removed_locked_tags = []
|
||||
end
|
||||
|
||||
self.rating_changed = prev.nil? || rating != prev.try(:rating)
|
||||
self.parent_changed = prev.nil? || parent_id != prev.try(:parent_id)
|
||||
self.source_changed = prev.nil? || source != prev.try(:source)
|
||||
end
|
||||
|
||||
def tag_array
|
||||
tags.split
|
||||
end
|
||||
|
||||
def locked_tag_array
|
||||
(locked_tags || "").split
|
||||
end
|
||||
|
||||
def presenter
|
||||
PostVersionPresenter.new(self)
|
||||
end
|
||||
@ -96,7 +121,7 @@ class PostArchive < ApplicationRecord
|
||||
# HACK: if all the post versions for this post have already been preloaded,
|
||||
# we can use that to avoid a SQL query.
|
||||
if association(:post).loaded? && post && post.association(:versions).loaded?
|
||||
post.versions.sort_by(&:version).reverse.find { |v| v.version < version }
|
||||
post.versions.sort_by(&:version).reverse.find {|v| v.version < version}
|
||||
else
|
||||
PostArchive.where("post_id = ? and version < ?", post_id, version).order("version desc").first
|
||||
end
|
||||
@ -132,21 +157,21 @@ class PostArchive < ApplicationRecord
|
||||
removed_tags = old_tags - new_tags
|
||||
|
||||
return {
|
||||
:added_tags => added_tags,
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_added_tags => added_tags - latest_tags,
|
||||
:obsolete_removed_tags => removed_tags & latest_tags,
|
||||
:unchanged_tags => new_tags & old_tags,
|
||||
:added_tags => added_tags,
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_added_tags => added_tags - latest_tags,
|
||||
:obsolete_removed_tags => removed_tags & latest_tags,
|
||||
:unchanged_tags => new_tags & old_tags,
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def changes
|
||||
delta = {
|
||||
:added_tags => added_tags,
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_removed_tags => [],
|
||||
:obsolete_added_tags => [],
|
||||
:unchanged_tags => []
|
||||
:added_tags => added_tags,
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_removed_tags => [],
|
||||
:obsolete_added_tags => [],
|
||||
:unchanged_tags => []
|
||||
}
|
||||
|
||||
return delta if post.nil?
|
||||
|
@ -1,165 +0,0 @@
|
||||
class PostVersion < ApplicationRecord
|
||||
belongs_to :post
|
||||
belongs_to :updater, :class_name => "User"
|
||||
before_validation :initialize_updater
|
||||
|
||||
module SearchMethods
|
||||
def for_user(user_id)
|
||||
where("updater_id = ?", user_id)
|
||||
end
|
||||
|
||||
def updater_name(name)
|
||||
where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.mb_chars.downcase)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
if params[:updater_name].present?
|
||||
q = q.updater_name(params[:updater_name])
|
||||
end
|
||||
|
||||
if params[:updater_id].present?
|
||||
q = q.where("updater_id = ?", params[:updater_id].to_i)
|
||||
end
|
||||
|
||||
if params[:post_id].present?
|
||||
q = q.where("post_id = ?", params[:post_id].to_i)
|
||||
end
|
||||
|
||||
if params[:start_id].present?
|
||||
q = q.where("id <= ?", params[:start_id].to_i)
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
|
||||
def self.create_from_post(post)
|
||||
if post.created_at == post.updated_at
|
||||
create_from_created_post(post)
|
||||
else
|
||||
create_from_updated_post(post)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def tag_array
|
||||
@tag_array ||= tags.split
|
||||
end
|
||||
|
||||
def reload
|
||||
@tag_array = nil
|
||||
super
|
||||
end
|
||||
|
||||
def diff(version)
|
||||
latest_tags = post.tag_array
|
||||
latest_tags << "rating:#{post.rating}" if post.rating.present?
|
||||
latest_tags << "parent:#{post.parent_id}" if post.parent_id.present?
|
||||
latest_tags << "source:#{post.source}" if post.source.present?
|
||||
|
||||
new_tags = tag_array
|
||||
new_tags << "rating:#{rating}" if rating.present?
|
||||
new_tags << "parent:#{parent_id}" if parent_id.present?
|
||||
new_tags << "source:#{source}" if source.present?
|
||||
|
||||
old_tags = version.present? ? version.tag_array : []
|
||||
if version.present?
|
||||
old_tags << "rating:#{version.rating}" if version.rating.present?
|
||||
old_tags << "parent:#{version.parent_id}" if version.parent_id.present?
|
||||
old_tags << "source:#{version.source}" if version.source.present?
|
||||
end
|
||||
|
||||
added_tags = new_tags - old_tags
|
||||
removed_tags = old_tags - new_tags
|
||||
|
||||
return {
|
||||
:added_tags => added_tags,
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_added_tags => added_tags - latest_tags,
|
||||
:obsolete_removed_tags => removed_tags & latest_tags,
|
||||
:unchanged_tags => new_tags & old_tags,
|
||||
}
|
||||
end
|
||||
|
||||
def changes
|
||||
@changes ||= diff(previous)
|
||||
end
|
||||
|
||||
def added_tags
|
||||
changes[:added_tags].join(" ")
|
||||
end
|
||||
|
||||
def removed_tags
|
||||
changes[:removed_tags].join(" ")
|
||||
end
|
||||
|
||||
def obsolete_added_tags
|
||||
changes[:obsolete_added_tags].join(" ")
|
||||
end
|
||||
|
||||
def obsolete_removed_tags
|
||||
changes[:obsolete_removed_tags].join(" ")
|
||||
end
|
||||
|
||||
def unchanged_tags
|
||||
changes[:unchanged_tags].join(" ")
|
||||
end
|
||||
|
||||
def previous
|
||||
if updated_at.to_i == Time.zone.parse("2007-03-14T19:38:12Z").to_i
|
||||
# Old post versions which didn't have updated_at set correctly
|
||||
PostVersion.where("post_id = ? and updated_at = ? and id < ?", post_id, updated_at, id).order("updated_at desc, id desc").first
|
||||
else
|
||||
PostVersion.where("post_id = ? and updated_at < ?", post_id, updated_at).order("updated_at desc, id desc").first
|
||||
end
|
||||
end
|
||||
|
||||
def truncated_source
|
||||
source.gsub(/^http:\/\//, "").sub(/\/.+/, "")
|
||||
end
|
||||
|
||||
def undo
|
||||
changes = diff(previous)
|
||||
added = changes[:added_tags] - changes[:obsolete_added_tags]
|
||||
removed = changes[:removed_tags] - changes[:obsolete_removed_tags]
|
||||
|
||||
added.each do |tag|
|
||||
if tag =~ /^source:/
|
||||
post.source = ""
|
||||
elsif tag =~ /^parent:/
|
||||
post.parent_id = nil
|
||||
else
|
||||
escaped_tag = Regexp.escape(tag)
|
||||
post.tag_string = post.tag_string.sub(/(?:\A| )#{escaped_tag}(?:\Z| )/, " ").strip
|
||||
end
|
||||
end
|
||||
removed.each do |tag|
|
||||
if tag =~ /^source:(.+)$/
|
||||
post.source = $1
|
||||
else
|
||||
post.tag_string = "#{post.tag_string} #{tag}".strip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def undo!
|
||||
undo
|
||||
post.save!
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
super + [:added_tags, :removed_tags, :obsolete_added_tags, :obsolete_removed_tags, :unchanged_tags, :updater_name]
|
||||
end
|
||||
end
|
@ -1,9 +1 @@
|
||||
if Danbooru.config.aws_ses_enabled? && Rails.env == "production"
|
||||
Rails.application.config.action_mailer.smtp_settings = {
|
||||
:address => Danbooru.config.aws_ses_options[:smtp_server_name],
|
||||
:user_name => Danbooru.config.aws_ses_options[:ses_smtp_user_name],
|
||||
:password => Danbooru.config.aws_ses_options[:ses_smtp_password],
|
||||
:authentication => :login,
|
||||
:enable_starttls_auto => true
|
||||
}
|
||||
end
|
||||
|
||||
|
30
db/migrate/20190510184237_add_post_versions.rb
Normal file
30
db/migrate/20190510184237_add_post_versions.rb
Normal file
@ -0,0 +1,30 @@
|
||||
class AddPostVersions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table "post_versions", :force => true do |t|
|
||||
t.integer "post_id", :null => false
|
||||
t.text "tags", :null => false
|
||||
t.text "added_tags", :null => false, :array => true, :default => []
|
||||
t.text "removed_tags", :null => false, :array => true, :default => []
|
||||
t.text "locked_tags", null: true
|
||||
t.text "added_locked_tags", null: false, array: true, default: []
|
||||
t.text "removed_locked_tags", null: false, array: true, default: []
|
||||
t.integer "updater_id"
|
||||
t.inet "updater_ip_addr", :limit => nil, :null => true
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "rating", :limit => 1
|
||||
t.boolean "rating_changed", :null => false, :default => false
|
||||
t.integer "parent_id"
|
||||
t.boolean "parent_changed", :null => false, :default => false
|
||||
t.text "source"
|
||||
t.boolean "source_changed", :null => false, :default => false
|
||||
t.text "description", null: true
|
||||
t.boolean "description_changed", null: false, default: false
|
||||
t.integer "version", :null => false, :default => 1
|
||||
end
|
||||
|
||||
add_index "post_versions", :post_id
|
||||
add_index "post_versions", :updated_at
|
||||
add_index "post_versions", :updater_id
|
||||
add_index "post_versions", :updater_ip_addr
|
||||
end
|
||||
end
|
26
db/migrate/20190510184245_add_pool_versions.rb
Normal file
26
db/migrate/20190510184245_add_pool_versions.rb
Normal file
@ -0,0 +1,26 @@
|
||||
class AddPoolVersions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table "pool_versions", :force => true do |t|
|
||||
t.integer "pool_id", :null => false
|
||||
t.integer "post_ids", :array => true, :default => [], :null => false
|
||||
t.integer "added_post_ids", :array => true, :default => [], :null => false
|
||||
t.integer "removed_post_ids", :array => true, :default => [], :null => false
|
||||
t.integer "updater_id"
|
||||
t.inet "updater_ip_addr", :limit => nil
|
||||
t.text "description"
|
||||
t.boolean "description_changed", :default => false, :null => false
|
||||
t.text "name"
|
||||
t.boolean "name_changed", :default => false, :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "is_active", :boolean, :default => true, :null => false
|
||||
t.boolean "is_deleted", :boolean, :default => false, :null => false
|
||||
t.string "category"
|
||||
t.integer "version", :default => 1, :null => false
|
||||
end
|
||||
|
||||
add_index "pool_versions", :pool_id
|
||||
add_index "pool_versions", :updater_id
|
||||
add_index "pool_versions", :updater_ip_addr
|
||||
end
|
||||
end
|
175
db/structure.sql
175
db/structure.sql
@ -1416,6 +1416,51 @@ CREATE SEQUENCE public.pixiv_ugoira_frame_data_id_seq
|
||||
ALTER SEQUENCE public.pixiv_ugoira_frame_data_id_seq OWNED BY public.pixiv_ugoira_frame_data.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_versions; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.pool_versions (
|
||||
id bigint NOT NULL,
|
||||
pool_id integer NOT NULL,
|
||||
post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
||||
added_post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
||||
removed_post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
||||
updater_id integer,
|
||||
updater_ip_addr inet,
|
||||
description text,
|
||||
description_changed boolean DEFAULT false NOT NULL,
|
||||
name text,
|
||||
name_changed boolean DEFAULT false NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
is_active boolean DEFAULT true NOT NULL,
|
||||
"boolean" boolean DEFAULT false NOT NULL,
|
||||
is_deleted boolean DEFAULT false NOT NULL,
|
||||
category character varying,
|
||||
version integer DEFAULT 1 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.pool_versions_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.pool_versions_id_seq OWNED BY public.pool_versions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@ -1752,6 +1797,53 @@ CREATE UNLOGGED TABLE public.post_updates (
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.post_versions (
|
||||
id bigint NOT NULL,
|
||||
post_id integer NOT NULL,
|
||||
tags text NOT NULL,
|
||||
added_tags text[] DEFAULT '{}'::text[] NOT NULL,
|
||||
removed_tags text[] DEFAULT '{}'::text[] NOT NULL,
|
||||
locked_tags text,
|
||||
added_locked_tags text[] DEFAULT '{}'::text[] NOT NULL,
|
||||
removed_locked_tags text[] DEFAULT '{}'::text[] NOT NULL,
|
||||
updater_id integer,
|
||||
updater_ip_addr inet,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
rating character varying(1),
|
||||
rating_changed boolean DEFAULT false NOT NULL,
|
||||
parent_id integer,
|
||||
parent_changed boolean DEFAULT false NOT NULL,
|
||||
source text,
|
||||
source_changed boolean DEFAULT false NOT NULL,
|
||||
description text,
|
||||
description_changed boolean DEFAULT false NOT NULL,
|
||||
version integer DEFAULT 1 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.post_versions_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.post_versions_id_seq OWNED BY public.post_versions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
@ -2817,6 +2909,13 @@ ALTER TABLE ONLY public.notes ALTER COLUMN id SET DEFAULT nextval('public.notes_
|
||||
ALTER TABLE ONLY public.pixiv_ugoira_frame_data ALTER COLUMN id SET DEFAULT nextval('public.pixiv_ugoira_frame_data_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_versions id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.pool_versions ALTER COLUMN id SET DEFAULT nextval('public.pool_versions_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@ -2880,6 +2979,13 @@ ALTER TABLE ONLY public.post_set_maintainers ALTER COLUMN id SET DEFAULT nextval
|
||||
ALTER TABLE ONLY public.post_sets ALTER COLUMN id SET DEFAULT nextval('public.post_sets_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.post_versions ALTER COLUMN id SET DEFAULT nextval('public.post_versions_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
@ -3309,6 +3415,14 @@ ALTER TABLE ONLY public.pixiv_ugoira_frame_data
|
||||
ADD CONSTRAINT pixiv_ugoira_frame_data_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pool_versions pool_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.pool_versions
|
||||
ADD CONSTRAINT pool_versions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: pools pools_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@ -3381,6 +3495,14 @@ ALTER TABLE ONLY public.post_sets
|
||||
ADD CONSTRAINT post_sets_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_versions post_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.post_versions
|
||||
ADD CONSTRAINT post_versions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: post_votes post_votes_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
@ -4052,6 +4174,27 @@ CREATE INDEX index_notes_on_post_id ON public.notes USING btree (post_id);
|
||||
CREATE UNIQUE INDEX index_pixiv_ugoira_frame_data_on_post_id ON public.pixiv_ugoira_frame_data USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pool_versions_on_pool_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_pool_versions_on_pool_id ON public.pool_versions USING btree (pool_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pool_versions_on_updater_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_pool_versions_on_updater_id ON public.pool_versions USING btree (updater_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pool_versions_on_updater_ip_addr; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_pool_versions_on_updater_ip_addr ON public.pool_versions USING btree (updater_ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_pools_on_creator_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -4192,6 +4335,34 @@ CREATE INDEX index_post_replacements_on_creator_id ON public.post_replacements U
|
||||
CREATE INDEX index_post_replacements_on_post_id ON public.post_replacements USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_versions_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_versions_on_post_id ON public.post_versions USING btree (post_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_versions_on_updated_at; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_versions_on_updated_at ON public.post_versions USING btree (updated_at);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_versions_on_updater_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_versions_on_updater_id ON public.post_versions USING btree (updater_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_versions_on_updater_ip_addr; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_post_versions_on_updater_ip_addr ON public.post_versions USING btree (updater_ip_addr);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_post_votes_on_user_id_and_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@ -4885,6 +5056,8 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20190427163107'),
|
||||
('20190427181805'),
|
||||
('20190428132152'),
|
||||
('20190430120155');
|
||||
('20190430120155'),
|
||||
('20190510184237'),
|
||||
('20190510184245');
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user