diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js
index 144dcd003..7736247f9 100644
--- a/app/assets/javascripts/posts.js
+++ b/app/assets/javascripts/posts.js
@@ -540,18 +540,20 @@
}
Danbooru.Post.initialize_saved_searches = function() {
- $("#saved_search_category").autocomplete({
- minLength: 1,
+ $("#saved_search_labels").autocomplete({
+ minLength: 2,
source: function(req, resp) {
$.ajax({
- url: "/saved_searches/categories.json",
+ url: "/saved_searches/labels.json",
+ data: {
+ label: req.term
+ },
method: "get",
success: function(data) {
resp($.map(data, function(saved_search) {
- var category = saved_search.category === null ? "uncategorized" : saved_search.category;
return {
- label: category,
- value: category
+ label: saved_search.replace(/_/g, " "),
+ value: saved_search
};
}));
}
@@ -575,7 +577,7 @@
});
$("#save-search").click(function() {
- if (Danbooru.meta("disable-categorized-saved-searches") === "false") {
+ if (Danbooru.meta("disable-labeled-saved-searches") === "false") {
$("#save-search-dialog").dialog("open");
} else {
$.post(
diff --git a/app/assets/stylesheets/common/simple_form.scss b/app/assets/stylesheets/common/simple_form.scss
index 661c6c489..81b2616c4 100644
--- a/app/assets/stylesheets/common/simple_form.scss
+++ b/app/assets/stylesheets/common/simple_form.scss
@@ -16,6 +16,10 @@ form.simple_form {
width: 20em;
}
+ span.hint {
+ margin-left: 1em;
+ }
+
textarea {
width: 70%;
font-size: 1.2em;
diff --git a/app/assets/stylesheets/common/tables.scss b/app/assets/stylesheets/common/tables.scss
index a12b55e64..32877aa73 100644
--- a/app/assets/stylesheets/common/tables.scss
+++ b/app/assets/stylesheets/common/tables.scss
@@ -19,7 +19,7 @@ table.striped {
}
}
- .number {
+ .number, .links {
text-align: right;
}
diff --git a/app/controllers/saved_searches_controller.rb b/app/controllers/saved_searches_controller.rb
index 7e1d96c6c..6e9cfc039 100644
--- a/app/controllers/saved_searches_controller.rb
+++ b/app/controllers/saved_searches_controller.rb
@@ -5,9 +5,11 @@ class SavedSearchesController < ApplicationController
respond_to :html, :xml, :json, :js
def index
- @saved_searches = saved_searches.order("tag_query")
- @categories = @saved_searches.group_by{|saved_search| saved_search.category.to_s}
- @categories = @categories.sort_by{|category, saved_searches| category.to_s}
+ @saved_searches = saved_searches.order("id")
+
+ if params[:label]
+ @saved_searches = saved_searches.labeled(params[:label])
+ end
respond_with(@saved_searches) do |format|
format.xml do
@@ -16,15 +18,18 @@ class SavedSearchesController < ApplicationController
end
end
- def categories
- @categories = saved_searches.select(:category).distinct
- respond_with(@categories)
+ def labels
+ @labels = SavedSearch.labels_for(CurrentUser.user.id)
+ if params[:label]
+ regexp = Regexp.compile(Regexp.escape(params[:label]))
+ @labels = @labels.grep(regexp)
+ end
+ respond_with(@labels)
end
def create
- @saved_search = saved_searches.create(:tag_query => params[:saved_search_tags], :category => params[:saved_search_category])
-
- if params[:saved_search_disable_categories]
+ @saved_search = saved_searches.create(:query => params[:saved_search_tags], :label_string => params[:saved_search_labels])
+ if params[:saved_search_disable_labels]
CurrentUser.disable_categorized_saved_searches = true
CurrentUser.save
end
diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb
index 2e552557a..924df4f2d 100644
--- a/app/models/saved_search.rb
+++ b/app/models/saved_search.rb
@@ -1,6 +1,4 @@
class SavedSearch < ActiveRecord::Base
- UNCATEGORIZED_NAME = "uncategorized"
-
module ListbooruMethods
extend ActiveSupport::Concern
@@ -17,140 +15,72 @@ class SavedSearch < ActiveRecord::Base
SqsService.new(Danbooru.config.aws_sqs_saved_search_url)
end
- def refresh_listbooru(user_id)
- return false unless enabled?
-
- sqs_service.send_message("refresh\n#{user_id}")
- end
-
- def reset_listbooru(user_id)
- return false unless enabled?
-
- user = User.find(user_id)
-
- sqs_service.send_message("delete\n#{user_id}\nall\n")
-
- user.saved_searches.each do |saved_search|
- sqs_service.send_message("create\n#{user_id}\n#{saved_search.category}\n#{saved_search.tag_query}", :delay_seconds => 30)
- end
-
- true
- end
-
- def rename_listbooru(user_id, old_category, new_category)
- return false unless enabled?
-
- sqs_service.send_message("rename\n#{user_id}\n#{old_category}\n#{new_category}\n")
-
- true
- end
-
- def post_ids(user_id, name = nil)
+ def post_ids(user_id, label = nil)
return [] unless enabled?
+ label = normalize_label(label) if label
- if name
- hash_name = Cache.hash(name)
- else
- hash_name = nil
- end
-
- body = Cache.get("ss-pids-#{user_id}-#{hash_name}", 60) do
- params = {
+ Cache.get("ss-#{user_id}-#{Cache.hash(label)}", 60) do
+ queries = SavedSearch.queries_for(user_id, label)
+ json = {
"key" => Danbooru.config.listbooru_auth_key,
- "user_id" => user_id
- }
+ "queries" => queries
+ }.to_json
- if name == UNCATEGORIZED_NAME
- params["name"] = nil
- elsif name.present?
- params["name"] = name
- end
+ uri = URI.parse("#{Danbooru.config.listbooru_server}/v2/search")
- uri = URI.parse("#{Danbooru.config.listbooru_server}/users")
- uri.query = URI.encode_www_form(params)
-
- Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.is_a?(URI::HTTPS)) do |http|
- resp = http.request_get(uri.request_uri)
+ body = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.is_a?(URI::HTTPS)) do |http|
+ resp = http.request_post(uri.request_uri, json)
if resp.is_a?(Net::HTTPSuccess)
resp.body
else
raise "HTTP error code: #{resp.code} #{resp.message}"
end
end
+
+ body.to_s.scan(/\d+/).map(&:to_i)
end
-
- body.to_s.scan(/\d+/).map(&:to_i)
end
end
-
- def update_listbooru_on_create
- return unless SavedSearch.enabled?
- return unless user.is_gold?
-
- SavedSearch.sqs_service.send_message("create\n#{user_id}\n#{category}\n#{tag_query}")
- end
-
- def update_listbooru_on_destroy
- return unless SavedSearch.enabled?
-
- SavedSearch.sqs_service.send_message("delete\n#{user_id}\n#{category}\n#{tag_query}")
- end
-
- def update_listbooru_on_update
- return unless SavedSearch.enabled?
- return unless user.is_gold?
-
- SavedSearch.sqs_service.send_message("update\n#{user_id}\n#{category_was}\n#{tag_query_was}\n#{category}\n#{tag_query}")
- end
end
include ListbooruMethods
belongs_to :user
- validates :tag_query, :presence => true
+ validates :query, :presence => true
validate :validate_count
- attr_accessible :tag_query, :category
+ attr_accessible :query, :label_string
before_create :update_user_on_create
- before_update :update_listbooru_on_update
after_destroy :update_user_on_destroy
- after_create :update_listbooru_on_create
- after_destroy :update_listbooru_on_destroy
- validates_uniqueness_of :tag_query, :scope => :user_id
+ after_save {|rec| Cache.delete(SavedSearch.cache_key(rec.user_id))}
+ after_destroy {|rec| Cache.delete(SavedSearch.cache_key(rec.user_id))}
before_validation :normalize
+ scope :labeled, lambda {|label| where("labels @> string_to_array(?, '~~~~')", label)}
- def self.tagged(tags)
- where(:tag_query => normalize(tags)).first
+ def self.normalize_label(label)
+ label.strip.downcase.gsub(/[[:space:]]/, "_")
end
- def self.normalize(tag_query)
- Tag.scan_query(tag_query).join(" ")
+ def self.labels_for(user_id)
+ Cache.get(cache_key(user_id)) do
+ SavedSearch.where(user_id: user_id).order("label").pluck("distinct unnest(labels) as label")
+ end
end
- def self.normalize_category(category)
- category.to_s.strip.gsub(/\s+/, "_").downcase
+ def self.cache_key(user_id)
+ "ss-labels-#{user_id}"
end
- def self.rename(user_id, old_category, new_category)
- user = User.find(user_id)
- old_category = normalize_category(old_category)
- new_category = normalize_category(new_category)
- user.saved_searches.where(category: old_category).update_all(category: new_category)
- rename_listbooru(user_id, old_category, new_category)
- end
-
- def self.categories_for(user)
- user.saved_searches.pluck("distinct category").map do |x|
- if x.blank?
- SavedSearch::UNCATEGORIZED_NAME
- else
- x
- end
+ def self.queries_for(user_id, label = nil, options = {})
+ if label
+ SavedSearch.where(user_id: user_id).labeled(label).pluck("distinct query")
+ else
+ SavedSearch.where(user_id: user_id).pluck("distinct query")
end
end
def normalize
- self.category = SavedSearch.normalize_category(category) if category
- self.tag_query = SavedSearch.normalize(tag_query)
+ self.query = query_array.sort.join(" ")
+ self.labels = labels.map {|x| SavedSearch.normalize_label(x)}.reject {|x| x.blank?}
end
def validate_count
@@ -171,7 +101,15 @@ class SavedSearch < ActiveRecord::Base
end
end
- def tag_query_array
- Tag.scan_tags(tag_query)
+ def query_array
+ Tag.scan_tags(query)
+ end
+
+ def label_string
+ labels.join(" ")
+ end
+
+ def label_string=(val)
+ self.labels = val.scan(/\S+/).map {|x| SavedSearch.normalize_label(x)}
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 68e633f9f..1e9eeb41d 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -849,24 +849,6 @@ class User < ActiveRecord::Base
end
end
- module SavedSearchMethods
- def unique_saved_search_categories
- if SavedSearch.enabled?
- categories = saved_searches.pluck(:category)
-
- if categories.any? {|x| x.blank?}
- categories.reject! {|x| x.blank?}
- categories.unshift(SavedSearch::UNCATEGORIZED_NAME)
- end
-
- categories.uniq!
- categories
- else
- []
- end
- end
- end
-
module SockPuppetMethods
def notify_sock_puppets
sock_puppet_suspects.each do |user|
@@ -895,7 +877,6 @@ class User < ActiveRecord::Base
include CountMethods
extend SearchMethods
include StatisticsMethods
- include SavedSearchMethods
def initialize_default_image_size
self.default_image_size = "large"
diff --git a/app/presenters/post_set_presenters/post.rb b/app/presenters/post_set_presenters/post.rb
index e3b600f01..0b4dbd07b 100644
--- a/app/presenters/post_set_presenters/post.rb
+++ b/app/presenters/post_set_presenters/post.rb
@@ -12,7 +12,7 @@ module PostSetPresenters
if post_set.is_pattern_search?
pattern_tags
elsif post_set.is_saved_search?
- SavedSearch.categories_for(CurrentUser.user).map {|x| "search:#{x}"}
+ SavedSearch.labels_for(CurrentUser.user.id).map {|x| "search:#{x}"}
elsif post_set.is_tag_subscription?
post_set.tag_subscription_tags
elsif post_set.is_single_tag?
@@ -56,8 +56,8 @@ module PostSetPresenters
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
end
- def saved_search_tags
- SavedSearch.categories_for(CurrentUser.user).map {|x| "search:#{x}"}
+ def saved_search_labels
+ SavedSearch.labels_for(CurrentUser.user.id).map {|x| "search:#{x}"}
end
def tag_list_html(template, options = {})
diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb
index 5d14e6c3c..f757ee6b4 100644
--- a/app/presenters/user_presenter.rb
+++ b/app/presenters/user_presenter.rb
@@ -221,9 +221,9 @@ class UserPresenter
end
end
- def saved_search_categories
+ def saved_search_labels
if CurrentUser.user.id == user.id
- user.unique_saved_search_categories
+ SavedSearch.labels_for(CurrentUser.user.id)
else
[]
end
diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb
index 9ef528a5f..ed08352ec 100644
--- a/app/views/layouts/default.html.erb
+++ b/app/views/layouts/default.html.erb
@@ -22,7 +22,7 @@
-
+
<%= auto_discovery_link_tag :atom, posts_path(:format => "atom", :tags => params[:tags]) %>
<%= stylesheet_link_tag "application", :media => "screen" %>
<% if CurrentUser.user.custom_style.present? %>
diff --git a/app/views/posts/index.html.erb b/app/views/posts/index.html.erb
index 66b1c03ae..c18f7ed1c 100644
--- a/app/views/posts/index.html.erb
+++ b/app/views/posts/index.html.erb
@@ -52,7 +52,11 @@
<% end %>
<% end %>
- <%= render "posts/partials/common/secondary_links" %>
+ <% if params[:tags] =~ /search:/ %>
+ <%= render "saved_searches/secondary_links" %>
+ <% else %>
+ <%= render "posts/partials/common/secondary_links" %>
+ <% end %>
<%= post_search_count_js %>
diff --git a/app/views/posts/partials/index/_related.html.erb b/app/views/posts/partials/index/_related.html.erb
index 345f16176..393a5719a 100644
--- a/app/views/posts/partials/index/_related.html.erb
+++ b/app/views/posts/partials/index/_related.html.erb
@@ -7,10 +7,6 @@
<%= link_to "Manage subscriptions", tag_subscriptions_path %>
<% end %>
- <% if @post_set.is_saved_search? %>
- <%= link_to "Manage saved searches", saved_searches_path %>
- <% end %>
-
<%= link_to "Random post", random_posts_path(:tags => params[:tags]), :id => "random-post", :rel => "nofollow" %>
<%= link_to "Mobile version", mobile_posts_path(:tags => params[:tags]) %>
diff --git a/app/views/saved_search_category_changes/new.html.erb b/app/views/saved_search_category_changes/new.html.erb
deleted file mode 100644
index a18edda63..000000000
--- a/app/views/saved_search_category_changes/new.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
Change Category
-
- <%= form_tag(saved_search_category_change_path, :class => "simple_form") do %>
-
-
- <%= text_field_tag "old", params[:old] %>
-
-
-
-
- <%= text_field_tag "new" %>
-
-
- <%= submit_tag %>
- <% end %>
-
-
-
-<%= render "saved_searches/secondary_links" %>
-
-<% content_for(:page_title) do %>
- Edit Category - <%= Danbooru.config.app_name %>
-<% end %>
diff --git a/app/views/saved_searches/_interface.html.erb b/app/views/saved_searches/_interface.html.erb
index 69f0e8ce4..1720a4499 100644
--- a/app/views/saved_searches/_interface.html.erb
+++ b/app/views/saved_searches/_interface.html.erb
@@ -8,12 +8,11 @@
<%= hidden_field_tag "saved_search_tags", params[:tags] %>
-
+
+ <%= text_field_tag "saved_search_labels", "" %>
-
+
<% end %>
<% end %>
\ No newline at end of file
diff --git a/app/views/saved_searches/_secondary_links.html.erb b/app/views/saved_searches/_secondary_links.html.erb
index 8a6c57c64..0b221881e 100644
--- a/app/views/saved_searches/_secondary_links.html.erb
+++ b/app/views/saved_searches/_secondary_links.html.erb
@@ -1,6 +1,6 @@
<% content_for(:secondary_links) do %>
<% end %>
diff --git a/app/views/saved_searches/create.js.erb b/app/views/saved_searches/create.js.erb
index 0755c27a3..87573ac1c 100644
--- a/app/views/saved_searches/create.js.erb
+++ b/app/views/saved_searches/create.js.erb
@@ -1,5 +1,5 @@
<% if @saved_search.errors.any? %>
Danbooru.error("<%= j @saved_search.errors.full_messages.join(', ') %>");
<% else %>
- Danbooru.notice("Search '<%= j @saved_search.tag_query %>' was saved");
+ Danbooru.notice("Search '<%= j @saved_search.query %>' was saved");
<% end %>
diff --git a/app/views/saved_searches/destroy.js.erb b/app/views/saved_searches/destroy.js.erb
index 97a5fc57e..ea5b41166 100644
--- a/app/views/saved_searches/destroy.js.erb
+++ b/app/views/saved_searches/destroy.js.erb
@@ -1,4 +1,4 @@
-Danbooru.notice("Search '<%= j @saved_search.tag_query %>' was deleted");
+Danbooru.notice("Search '<%= j @saved_search.query %>' was deleted");
$("#saved-searches-nav").html("<%= j render('saved_searches/interface', :saved_searches => CurrentUser.user.saved_searches) %>");
Danbooru.Post.initialize_saved_searches();
$("#saved-search-<%= @saved_search.id %>").remove();
diff --git a/app/views/saved_searches/edit.html.erb b/app/views/saved_searches/edit.html.erb
index 7e8eb2c85..1005282a0 100644
--- a/app/views/saved_searches/edit.html.erb
+++ b/app/views/saved_searches/edit.html.erb
@@ -5,9 +5,9 @@
<%= error_messages_for :saved_search %>
<%= simple_form_for(@saved_search) do |f| %>
- <%= f.input :tag_query %>
- <%= f.input :category %>
- <%= f.button :submit, :data => { :disable_with => "Submitting..." } %>
+ <%= f.input :query %>
+ <%= f.input :label_string, :label => "Labels", :hint => "A list of tags to help categorize this search. Space delimited." %>
+ <%= f.button :submit, :value => "Submit", :data => { :disable_with => "Submitting..." } %>
<% end %>
diff --git a/app/views/saved_searches/index.html.erb b/app/views/saved_searches/index.html.erb
index 6a37c837c..807e8e643 100644
--- a/app/views/saved_searches/index.html.erb
+++ b/app/views/saved_searches/index.html.erb
@@ -1,37 +1,38 @@
-
Saved Searches
+
+ Saved Searches
+ <% if params[:label] %>
+ (<%= params[:label] %>)
+ <% end %>
+
- <% @categories.each do |category, saved_searches| %>
-
- <% if category.present? %>
- <%= link_to_if SavedSearch.posts_search_available?, category.tr("_", " "), posts_path(:tags => "search:#{category}") %>
- (<%= link_to "rename", new_saved_search_category_change_path(:old => category) %>)
- <% else %>
- <%= link_to_if SavedSearch.posts_search_available?, SavedSearch::UNCATEGORIZED_NAME, posts_path(:tags => "search:#{SavedSearch::UNCATEGORIZED_NAME}") %>
- <% end %>
-
-
-
-
- | Tags |
- |
+
+
+
+ | Query |
+ Labels |
+ |
+
+
+
+
+ <% @saved_searches.each do |ss| %>
+
+ | <%= link_to ss.query, posts_path(:tags => ss.query) %> |
+
+ <% ss.labels.each do |label| %>
+ <%= link_to label, posts_path(:tags => "search:#{label}") %>
+ <% end %>
+ |
+
+ <%= link_to "edit", edit_saved_search_path(ss) %>
+ | <%= link_to "delete", saved_search_path(ss), :method => :delete, :remote => true %>
+ |
-
-
-
- <% saved_searches.each do |saved_search| %>
-
- | <%= link_to saved_search.tag_query, posts_path(:tags => saved_search.tag_query) %> |
-
- <%= link_to "edit", edit_saved_search_path(saved_search) %>
- | <%= link_to "delete", saved_search_path(saved_search), :method => :delete, :remote => true %>
- |
-
- <% end %>
-
-
- <% end %>
+ <% end %>
+
+
diff --git a/app/views/users/_post_summary.html.erb b/app/views/users/_post_summary.html.erb
index 1266c9d91..134da3d38 100644
--- a/app/views/users/_post_summary.html.erb
+++ b/app/views/users/_post_summary.html.erb
@@ -30,30 +30,17 @@
<% end %>
-<% presenter.subscriptions.each do |subscription| %>
-
-
- Subscription: <%= link_to subscription.pretty_name, posts_path(:tags => "sub:#{user.name}:#{subscription.name}") %>
-
-
-
- <% presenter.posts_for_subscription(subscription).each do |post| %>
- <%= PostPresenter.preview(post, :tags => "sub:#{user.name}:#{subscription.name}") %>
- <% end %>
-
-
-<% end %>
-
<% if CurrentUser.user.id == @user.id && @user.has_saved_searches? && @user.is_gold? %>
- <% presenter.saved_search_categories.each do |category| %>
-
+ <% presenter.saved_search_labels.each do |label| %>
+
- Saved Search: <%= link_to category, posts_path(:tags => "search:#{category}") %>
+ Saved Search: <%= link_to label, posts_path(:tags => "search:#{label}") %>
+ (<%= link_to "manage", saved_searches_path(label: label) %>)
- <% presenter.posts_for_saved_search_category(category).each do |post| %>
- <%= PostPresenter.preview(post, :tags => "search:#{category}") %>
+ <% presenter.posts_for_saved_search_category(label).each do |post| %>
+ <%= PostPresenter.preview(post, :tags => "search:#{label}") %>
<% end %>
diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb
index dfe64eb90..3e37d8e8e 100644
--- a/app/views/users/_statistics.html.erb
+++ b/app/views/users/_statistics.html.erb
@@ -122,19 +122,6 @@
Feedback |
<%= presenter.feedbacks(self) %> |
-
-
- | Subscriptions |
-
- <% presenter.subscriptions.each do |subscription| %>
-
- <%= link_to subscription.pretty_name, posts_path(:tags => "sub:#{user.name}:#{subscription.name}") %>
- –
- <%= presenter.tag_links_for_subscription(self, subscription) %>
-
- <% end %>
- |
-
<% if presenter.previous_names(self).present? %>
@@ -148,13 +135,26 @@
| Saved Searches |
- <% SavedSearch.categories_for(CurrentUser.user).each do |category| %>
- <%= link_to category, posts_path(tags: "search:#{category}") %>
+ <% SavedSearch.labels_for(CurrentUser.user.id).each do |label| %>
+ <%= link_to label, posts_path(tags: "search:#{label}") %>
<% end %>
|
<% end %>
+
+ | Subscriptions |
+
+ <% presenter.subscriptions.each do |subscription| %>
+
+ <%= link_to subscription.pretty_name, posts_path(:tags => "sub:#{user.name}:#{subscription.name}") %>
+ –
+ <%= presenter.tag_links_for_subscription(self, subscription) %>
+
+ <% end %>
+ |
+
+
| API Key |
diff --git a/config/routes.rb b/config/routes.rb
index df7fa94ee..c8877a524 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -235,10 +235,9 @@ Rails.application.routes.draw do
post "reports/post_versions_create" => "reports#post_versions_create"
resources :saved_searches, :except => [:show] do
collection do
- get :categories
+ get :labels
end
end
- resource :saved_search_category_change, :only => [:new, :create]
resource :session do
collection do
get :sign_out
diff --git a/db/migrate/20170314235626_add_tags_to_saved_searches.rb b/db/migrate/20170314235626_add_tags_to_saved_searches.rb
new file mode 100644
index 000000000..b1cfba068
--- /dev/null
+++ b/db/migrate/20170314235626_add_tags_to_saved_searches.rb
@@ -0,0 +1,7 @@
+class AddTagsToSavedSearches < ActiveRecord::Migration
+ def change
+ add_column :saved_searches, :labels, "text", array: true, null: false, default: []
+ add_index :saved_searches, :labels, using: :gin
+ rename_column :saved_searches, :tag_query, :query
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index 7cd5193a5..1873e5a11 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -777,6 +777,74 @@ CREATE SEQUENCE artists_id_seq
ALTER SEQUENCE artists_id_seq OWNED BY artists.id;
+--
+-- Name: bank_balances; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE bank_balances (
+ id integer NOT NULL,
+ user_id integer NOT NULL,
+ amount integer NOT NULL,
+ created_at timestamp without time zone NOT NULL,
+ updated_at timestamp without time zone NOT NULL,
+ nonce character varying NOT NULL
+);
+
+
+--
+-- Name: bank_balances_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE bank_balances_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: bank_balances_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE bank_balances_id_seq OWNED BY bank_balances.id;
+
+
+--
+-- Name: bank_transactions; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE bank_transactions (
+ id integer NOT NULL,
+ user_id integer NOT NULL,
+ amount integer NOT NULL,
+ nonce character varying NOT NULL,
+ type character varying NOT NULL,
+ data text,
+ created_at timestamp without time zone NOT NULL,
+ updated_at timestamp without time zone NOT NULL
+);
+
+
+--
+-- Name: bank_transactions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE bank_transactions_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: bank_transactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE bank_transactions_id_seq OWNED BY bank_transactions.id;
+
+
--
-- Name: bans; Type: TABLE; Schema: public; Owner: -
--
@@ -2838,11 +2906,12 @@ ALTER SEQUENCE posts_id_seq OWNED BY posts.id;
CREATE TABLE saved_searches (
id integer NOT NULL,
user_id integer,
- tag_query text,
+ query text,
name text,
category character varying,
created_at timestamp without time zone,
- updated_at timestamp without time zone
+ updated_at timestamp without time zone,
+ labels text[] DEFAULT '{}'::text[] NOT NULL
);
@@ -3415,6 +3484,20 @@ ALTER TABLE ONLY artist_versions ALTER COLUMN id SET DEFAULT nextval('artist_ver
ALTER TABLE ONLY artists ALTER COLUMN id SET DEFAULT nextval('artists_id_seq'::regclass);
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY bank_balances ALTER COLUMN id SET DEFAULT nextval('bank_balances_id_seq'::regclass);
+
+
+--
+-- Name: id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY bank_transactions ALTER COLUMN id SET DEFAULT nextval('bank_transactions_id_seq'::regclass);
+
+
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -4489,6 +4572,22 @@ ALTER TABLE ONLY artists
ADD CONSTRAINT artists_pkey PRIMARY KEY (id);
+--
+-- Name: bank_balances_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY bank_balances
+ ADD CONSTRAINT bank_balances_pkey PRIMARY KEY (id);
+
+
+--
+-- Name: bank_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY bank_transactions
+ ADD CONSTRAINT bank_transactions_pkey PRIMARY KEY (id);
+
+
--
-- Name: bans_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -4993,6 +5092,34 @@ CREATE INDEX index_artists_on_other_names_index ON artists USING gin (other_name
CREATE INDEX index_artists_on_other_names_trgm ON artists USING gin (other_names gin_trgm_ops);
+--
+-- Name: index_bank_balances_on_user_id; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX index_bank_balances_on_user_id ON bank_balances USING btree (user_id);
+
+
+--
+-- Name: index_bank_transactions_on_created_at; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_bank_transactions_on_created_at ON bank_transactions USING btree (created_at);
+
+
+--
+-- Name: index_bank_transactions_on_nonce; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE UNIQUE INDEX index_bank_transactions_on_nonce ON bank_transactions USING btree (nonce);
+
+
+--
+-- Name: index_bank_transactions_on_user_id; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_bank_transactions_on_user_id ON bank_transactions USING btree (user_id);
+
+
--
-- Name: index_bans_on_banner_id; Type: INDEX; Schema: public; Owner: -
--
@@ -6926,10 +7053,17 @@ CREATE INDEX index_saved_searches_on_category ON saved_searches USING btree (cat
--
--- Name: index_saved_searches_on_tag_query; Type: INDEX; Schema: public; Owner: -
+-- Name: index_saved_searches_on_labels; Type: INDEX; Schema: public; Owner: -
--
-CREATE INDEX index_saved_searches_on_tag_query ON saved_searches USING btree (tag_query);
+CREATE INDEX index_saved_searches_on_labels ON saved_searches USING gin (labels);
+
+
+--
+-- Name: index_saved_searches_on_query; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_saved_searches_on_query ON saved_searches USING btree (query);
--
@@ -7464,7 +7598,15 @@ INSERT INTO schema_migrations (version) VALUES ('20170112060921');
INSERT INTO schema_migrations (version) VALUES ('20170117233040');
+INSERT INTO schema_migrations (version) VALUES ('20170126020516');
+
+INSERT INTO schema_migrations (version) VALUES ('20170126214445');
+
INSERT INTO schema_migrations (version) VALUES ('20170218104710');
INSERT INTO schema_migrations (version) VALUES ('20170302014435');
+INSERT INTO schema_migrations (version) VALUES ('20170314204631');
+
+INSERT INTO schema_migrations (version) VALUES ('20170314235626');
+
diff --git a/script/fixes/044_initialized_saved_search_tags.rb b/script/fixes/044_initialized_saved_search_tags.rb
new file mode 100644
index 000000000..90501ebc2
--- /dev/null
+++ b/script/fixes/044_initialized_saved_search_tags.rb
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'config', 'environment'))
+
+ActiveRecord::Base.connection.execute("set statement_timeout = 0")
+
+SavedSearch.find_each do |ss|
+ ss.labels = [ss.category]
+ ss.save
+end
|