diff --git a/app/models/concerns/featureable.rb b/app/models/concerns/featureable.rb index 475cb76bb..0e16655f9 100644 --- a/app/models/concerns/featureable.rb +++ b/app/models/concerns/featureable.rb @@ -1,10 +1,11 @@ module Featureable extend ActiveSupport::Concern - included do - scope :featured, -> { where.not(featured_at: nil) } - before_save :update_featured_at - end + # TEMP: re-enable and expand coverage to include Journal, Issue, et al + # included do + # scope :featured, -> { where.not(featured_at: nil) } + # before_save :update_featured_at + # end module ClassMethods def for_index fallback_sort: { title: :asc }, fallback_locale: 'en' diff --git a/app/models/concerns/publishable.rb b/app/models/concerns/publishable.rb index 9ff351209..7a02601e8 100644 --- a/app/models/concerns/publishable.rb +++ b/app/models/concerns/publishable.rb @@ -5,10 +5,10 @@ module Publishable included do enum :publication_status, PUBLICATION_STATUSES enum :temp_publication_status, - { draft: :draft, published: :published }, - default: :draft, + { draft: 'draft', published: 'published' }, + # default: :draft, prefix: true - # validate: true, + # validate: true default_scope { order(published_at: :desc) } diff --git a/app/models/locale.rb b/app/models/locale.rb index 401cf247f..c42fb9849 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -10,10 +10,10 @@ class Locale < ApplicationRecord enum :language_direction, { ltr: 0, rtl: 1 } enum :temp_language_direction, - { ltr: :ltr, rtl: :rtl }, - default: :ltr, + { ltr: 'ltr', rtl: 'rtl' }, + # default: :ltr, prefix: true - # validate: true, + # validate: true default_scope { order abbreviation: :asc } diff --git a/app/models/user.rb b/app/models/user.rb index 87e6132e6..ab8632591 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,11 +5,11 @@ class User < ApplicationRecord ROLES = %i[author editor publisher].freeze enum :role, ROLES - enum :temp_roles, - { author: :author, editor: :editor, publisher: :publisher }, - default: :author, - prefix: true - # validate: true, + enum :temp_role, + { author: 'author', editor: 'editor', publisher: 'publisher' }, + # default: :author, + prefix: true + # validate: true validates :username, presence: true, uniqueness: true, on: %i[create update] diff --git a/config/application.rb b/config/application.rb index 4244396a0..1a8a0ec57 100644 --- a/config/application.rb +++ b/config/application.rb @@ -10,6 +10,9 @@ require_relative '../app/middlewares/rack/teapot' require 'rack/contrib' +# TEMP: enum backfill data migration class +require_relative '../db/data_migrate' + # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) diff --git a/db/data_migrate.rb b/db/data_migrate.rb new file mode 100644 index 000000000..04bbca8d5 --- /dev/null +++ b/db/data_migrate.rb @@ -0,0 +1,66 @@ +# rubocop:disable Metrics/MethodLength +class DataMigrate + class << self + def run + # locales + Locale.find_each do |locale| + locale.update! temp_language_direction: locale.language_direction + end + + # users + User.find_each do |user| + user.update! temp_role: user.role + end + + # "publishable" tables + Article.find_each do |article| + article.update! temp_publication_status: article.publication_status + end + + Book.find_each do |book| + book.update! temp_publication_status: book.publication_status + end + + Definition.find_each do |definition| + definition.update! temp_publication_status: definition.publication_status + end + + Episode.find_each do |episode| + episode.update! temp_publication_status: episode.publication_status + end + + Issue.find_each do |issue| + issue.update! temp_publication_status: issue.publication_status + end + + Journal.find_each do |journal| + journal.update! temp_publication_status: journal.publication_status + end + + Logo.find_each do |logo| + logo.update! temp_publication_status: logo.publication_status + end + + Page.find_each do |page| + page.update! temp_publication_status: page.publication_status + end + + Poster.find_each do |poster| + poster.update! temp_publication_status: poster.publication_status + end + + Sticker.find_each do |sticker| + sticker.update! temp_publication_status: sticker.publication_status + end + + Video.find_each do |video| + video.update! temp_publication_status: video.publication_status + end + + Zine.find_each do |zine| + zine.update! temp_publication_status: zine.publication_status + end + end + end +end +# rubocop:enable Metrics/MethodLength diff --git a/db/migrate/20240909064134_rename_column_temp_roles_on_users.rb b/db/migrate/20240909064134_rename_column_temp_roles_on_users.rb new file mode 100644 index 000000000..be07be7df --- /dev/null +++ b/db/migrate/20240909064134_rename_column_temp_roles_on_users.rb @@ -0,0 +1,5 @@ +class RenameColumnTempRolesOnUsers < ActiveRecord::Migration[7.2] + def change + rename_column :users, :temp_roles, :temp_role + end +end diff --git a/db/schema.rb b/db/schema.rb index fed2d7e95..489aef26e 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[7.2].define(version: 2024_09_09_055738) do +ActiveRecord::Schema[7.2].define(version: 2024_09_09_064134) do create_schema "heroku_ext" # These are extensions that must be enabled in order to support this database @@ -61,6 +61,8 @@ t.string "year" t.string "month" t.string "day" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "collection_id" t.string "short_path" t.text "image_mobile" @@ -75,8 +77,6 @@ t.integer "position" t.boolean "hide_from_index", default: false t.text "notes" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_articles_on_canonical_id" t.index ["collection_id"], name: "index_articles_on_collection_id" @@ -112,6 +112,8 @@ t.text "cover_style" t.text "binding_style" t.text "table_of_contents" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.boolean "back_image_present", default: false t.boolean "front_image_present", default: false t.boolean "lite_download_present", default: false @@ -131,8 +133,6 @@ t.datetime "featured_at", precision: nil t.integer "position" t.boolean "hide_from_index", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_books_on_canonical_id" end @@ -140,20 +140,22 @@ create_table "categories", id: :serial, force: :cascade do |t| t.string "name" t.string "slug" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false end create_table "categorizations", id: :serial, force: :cascade do |t| t.integer "category_id" t.integer "article_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false end create_table "definitions", force: :cascade do |t| t.string "title" t.text "content" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "locale", default: "en" t.integer "canonical_id" t.string "subtitle" @@ -161,11 +163,9 @@ t.string "draft_code" t.string "slug" t.integer "publication_status" - t.datetime "published_at" - t.datetime "featured_at" + t.datetime "published_at", precision: nil + t.datetime "featured_at", precision: nil t.boolean "featured_status", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_definitions_on_canonical_id" end @@ -187,6 +187,8 @@ t.string "audio_type", default: "audio/mpeg" t.string "tags" t.datetime "published_at", precision: nil + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "slug" t.string "published_at_tz", default: "Pacific Time (US & Canada)", null: false t.string "episode_number" @@ -194,8 +196,6 @@ t.integer "canonical_id" t.string "draft_code" t.integer "publication_status", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_episodes_on_canonical_id" t.index ["podcast_id"], name: "index_episodes_on_podcast_id" @@ -262,6 +262,8 @@ t.string "title" t.string "subtitle" t.text "description" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "slug" t.datetime "published_at", precision: nil t.integer "publication_status", default: 0, null: false @@ -274,8 +276,6 @@ t.integer "canonical_id" t.integer "position" t.boolean "hide_from_index", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_journals_on_canonical_id" end @@ -284,11 +284,11 @@ t.string "abbreviation" t.string "name_in_english" t.string "name" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "language_direction", default: 0 t.string "slug" t.integer "articles_count", default: 0 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_language_direction" end @@ -300,13 +300,13 @@ t.string "content_format" t.datetime "published_at", precision: nil t.text "summary" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "publication_status", default: 0, null: false t.string "locale", default: "en" t.integer "canonical_id" t.integer "position" t.boolean "hide_from_index", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_logos_on_canonical_id" end @@ -326,12 +326,12 @@ t.string "slug" t.string "draft_code" t.datetime "published_at", precision: nil + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "published_at_tz", default: "Pacific Time (US & Canada)", null: false t.integer "publication_status", default: 0, null: false t.string "locale", default: "en" t.integer "canonical_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_pages_on_canonical_id" end @@ -354,11 +354,11 @@ t.text "itunes_url" t.text "overcast_url" t.text "pocketcasts_url" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "episode_prefix" t.string "locale", default: "en" t.integer "canonical_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.index ["canonical_id"], name: "index_podcasts_on_canonical_id" end @@ -375,6 +375,8 @@ t.text "slug" t.string "height" t.string "width" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "depth" t.string "front_image_format", default: "jpg" t.string "back_image_format", default: "jpg" @@ -394,8 +396,6 @@ t.datetime "featured_at", precision: nil t.integer "position" t.boolean "hide_from_index", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_posters_on_canonical_id" end @@ -404,9 +404,9 @@ t.string "source_path" t.string "target_path" t.boolean "temporary" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "article_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false end create_table "stickers", force: :cascade do |t| @@ -435,14 +435,14 @@ t.boolean "back_color_download_present" t.boolean "back_black_and_white_download_present" t.integer "publication_status", default: 0, null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "locale", default: "en" t.integer "canonical_id" t.boolean "featured_status", default: false t.datetime "featured_at", precision: nil t.integer "position" t.boolean "hide_from_index", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_stickers_on_canonical_id" end @@ -456,18 +456,18 @@ create_table "taggings", id: :serial, force: :cascade do |t| t.integer "tag_id" t.integer "taggable_id" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "taggable_type" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false end create_table "tags", id: :serial, force: :cascade do |t| t.string "name" t.string "slug" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "locale", default: "en" t.integer "canonical_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.index ["canonical_id"], name: "index_tags_on_canonical_id" t.index ["name"], name: "index_tags_on_name", unique: true end @@ -475,10 +475,10 @@ create_table "users", id: :serial, force: :cascade do |t| t.string "username" t.string "password_digest" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.integer "role", default: 0, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.string "temp_roles" + t.string "temp_role" end create_table "videos", id: :serial, force: :cascade do |t| @@ -497,12 +497,12 @@ t.string "year" t.string "month" t.string "day" + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "published_at_tz", default: "Pacific Time (US & Canada)", null: false t.integer "publication_status", default: 0, null: false t.string "locale", default: "en" t.integer "canonical_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_videos_on_canonical_id" end @@ -550,14 +550,14 @@ t.boolean "screen_single_page_view_download_present" t.boolean "screen_two_page_view_download_present" t.integer "publication_status", default: 0, null: false + t.datetime "created_at", precision: nil, null: false + t.datetime "updated_at", precision: nil, null: false t.string "locale", default: "en" t.integer "canonical_id" t.boolean "featured_status", default: false t.datetime "featured_at", precision: nil t.integer "position" t.boolean "hide_from_index", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false t.string "temp_publication_status" t.index ["canonical_id"], name: "index_zines_on_canonical_id" end