diff --git a/app/models/article.rb b/app/models/article.rb index 7cf4ebd41..f619726a6 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -5,6 +5,7 @@ # id :bigint not null, primary key # content :text # description :text +# meta :jsonb # status :integer # title :string # views :integer diff --git a/app/views/api/v1/accounts/categories/_category.json.jbuilder b/app/views/api/v1/accounts/categories/_category.json.jbuilder index 2e4263722..17aecacd2 100644 --- a/app/views/api/v1/accounts/categories/_category.json.jbuilder +++ b/app/views/api/v1/accounts/categories/_category.json.jbuilder @@ -25,3 +25,5 @@ if category.root_category.present? json.partial! 'api/v1/accounts/categories/associated_category.json.jbuilder', category: category.root_category end end + +json.articles_count category.articles.published.try(:count) diff --git a/app/views/public/api/v1/models/_category.json.jbuilder b/app/views/public/api/v1/models/_category.json.jbuilder index ee3057ae3..6c611fc51 100644 --- a/app/views/public/api/v1/models/_category.json.jbuilder +++ b/app/views/public/api/v1/models/_category.json.jbuilder @@ -23,3 +23,5 @@ if category.root_category.present? json.partial! partial: 'associated_category', category: category.root_category end end + +json.articles_count category.articles.published.try(:count) diff --git a/db/migrate/20220720080126_add_meta_column_to_article.rb b/db/migrate/20220720080126_add_meta_column_to_article.rb new file mode 100644 index 000000000..6cb7ca23c --- /dev/null +++ b/db/migrate/20220720080126_add_meta_column_to_article.rb @@ -0,0 +1,5 @@ +class AddMetaColumnToArticle < ActiveRecord::Migration[6.1] + def change + add_column :articles, :meta, :jsonb, default: {} + end +end diff --git a/db/schema.rb b/db/schema.rb index df5950031..3b62a868b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_07_18_123938) do +ActiveRecord::Schema.define(version: 2022_07_20_080126) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" @@ -128,6 +128,7 @@ ActiveRecord::Schema.define(version: 2022_07_18_123938) do t.datetime "updated_at", precision: 6, null: false t.bigint "author_id" t.bigint "associated_article_id" + t.jsonb "meta", default: {} t.index ["associated_article_id"], name: "index_articles_on_associated_article_id" t.index ["author_id"], name: "index_articles_on_author_id" end