Skip to content

Commit

Permalink
Add Motor Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhbhatia committed Oct 25, 2024
1 parent ab91a53 commit 903dd94
Show file tree
Hide file tree
Showing 5 changed files with 497 additions and 9 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ gem "httparty"
gem "dotenv-rails"
gem "honeybadger"
gem "rack-cors"
gem "motor-admin"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]

Expand Down
20 changes: 20 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ar_lazy_preload (1.1.2)
rails (>= 5.2)
ast (2.4.2)
audited (5.7.0)
activerecord (>= 5.2, < 8.0)
activesupport (>= 5.2, < 8.0)
aws-eventstream (1.3.0)
aws-partitions (1.991.0)
aws-sdk-core (3.209.1)
Expand All @@ -119,6 +124,7 @@ GEM
msgpack (~> 1.2)
brotli (0.6.0)
builder (3.3.0)
cancancan (3.6.1)
capybara (3.40.0)
addressable
matrix
Expand Down Expand Up @@ -155,6 +161,8 @@ GEM
railties (>= 6.1)
drb (2.2.1)
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
factory_bot (6.5.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
Expand All @@ -176,6 +184,9 @@ GEM
rack-protection (>= 1.5.3, < 5.0.0)
rack-session (>= 1.0.2, < 3.0.0)
sanitize (< 7)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
graphiql-rails (1.10.1)
Expand Down Expand Up @@ -240,6 +251,13 @@ GEM
monetize (~> 1.9)
money (~> 6.13)
railties (>= 3.0)
motor-admin (0.4.31)
ar_lazy_preload (~> 1.0)
audited (~> 5.0)
cancancan (~> 3.0)
csv (>= 3.0)
fugit (~> 1.0)
rails (>= 5.2)
msgpack (1.7.3)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
Expand Down Expand Up @@ -286,6 +304,7 @@ GEM
nio4r (~> 2.0)
pundit (2.4.0)
activesupport (>= 3.0.0)
raabro (1.4.0)
racc (1.8.1)
rack (3.1.8)
rack-brotli (2.0.0)
Expand Down Expand Up @@ -488,6 +507,7 @@ DEPENDENCIES
jsbundling-rails
meta-tags
money-rails
motor-admin
omniauth (~> 2.1)
pagy
pg
Expand Down
14 changes: 6 additions & 8 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
sign_in: "login",
sign_out: "logout"
}

namespace :admin do
root "dashboard#index"
resources :posts, param: :slug
resources :creator_profiles, param: :slug
resources :stores, param: :slug
resources :products, param: :slug do
get :add_product_to_stripe, on: :member
authenticate(:admin_user) do
mount Motor::Admin => "/panel"
mount Flipper::UI.app(Flipper) => "/flipper"
mount Sidekiq::Web => "/sidekiq"
end
mount Flipper::UI.app(Flipper) => "/flipper"
mount Sidekiq::Web => "/sidekiq"
end

root "home#index"
get "about", to: "pages#about", as: "about"
get "for-creators", to: "pages#for_creators", as: "for_creators"
Expand Down
271 changes: 271 additions & 0 deletions db/migrate/20241024192032_install_motor_admin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
class InstallMotorAdmin < ActiveRecord::Migration[7.1]
def self.up
create_table :motor_queries do |t|
t.column :name, :string, null: false
t.column :description, :text
t.column :sql_body, :text, null: false
t.column :preferences, :text, null: false
t.column :author_id, :bigint
t.column :author_type, :string
t.column :deleted_at, :datetime

t.timestamps

t.index :updated_at
t.index 'name',
name: 'motor_queries_name_unique_index',
unique: true,
where: 'deleted_at IS NULL'
end

create_table :motor_dashboards do |t|
t.column :title, :string, null: false
t.column :description, :text
t.column :preferences, :text, null: false
t.column :author_id, :bigint
t.column :author_type, :string
t.column :deleted_at, :datetime

t.timestamps

t.index :updated_at
t.index 'title',
name: 'motor_dashboards_title_unique_index',
unique: true,
where: 'deleted_at IS NULL'
end

create_table :motor_forms do |t|
t.column :name, :string, null: false
t.column :description, :text
t.column :api_path, :text, null: false
t.column :http_method, :string, null: false
t.column :preferences, :text, null: false
t.column :author_id, :bigint
t.column :author_type, :string
t.column :deleted_at, :datetime
t.column :api_config_name, :string, null: false

t.timestamps

t.index :updated_at
t.index 'name',
name: 'motor_forms_name_unique_index',
unique: true,
where: 'deleted_at IS NULL'
end

create_table :motor_resources do |t|
t.column :name, :string, null: false, index: { unique: true }
t.column :preferences, :text, null: false

t.timestamps

t.index :updated_at
end

create_table :motor_configs do |t|
t.column :key, :string, null: false, index: { unique: true }
t.column :value, :text, null: false

t.timestamps

t.index :updated_at
end

create_table :motor_alerts do |t|
t.references :query, null: false, foreign_key: { to_table: :motor_queries }, index: true
t.column :name, :string, null: false
t.column :description, :text
t.column :to_emails, :text, null: false
t.column :is_enabled, :boolean, null: false, default: true
t.column :preferences, :text, null: false
t.column :author_id, :bigint
t.column :author_type, :string
t.column :deleted_at, :datetime

t.timestamps

t.index :updated_at
t.index 'name',
name: 'motor_alerts_name_unique_index',
unique: true,
where: 'deleted_at IS NULL'
end

create_table :motor_alert_locks do |t|
t.references :alert, null: false, foreign_key: { to_table: :motor_alerts }
t.column :lock_timestamp, :string, null: false

t.timestamps

t.index %i[alert_id lock_timestamp], unique: true
end

create_table :motor_tags do |t|
t.column :name, :string, null: false

t.timestamps

t.index 'name',
name: 'motor_tags_name_unique_index',
unique: true
end

create_table :motor_taggable_tags do |t|
t.references :tag, null: false, foreign_key: { to_table: :motor_tags }, index: true
t.column :taggable_id, :bigint, null: false
t.column :taggable_type, :string, null: false

t.index %i[taggable_id taggable_type tag_id],
name: 'motor_polymorphic_association_tag_index',
unique: true
end

create_table :motor_audits do |t|
t.column :auditable_id, :string
t.column :auditable_type, :string
t.column :associated_id, :string
t.column :associated_type, :string
t.column :user_id, :bigint
t.column :user_type, :string
t.column :username, :string
t.column :action, :string
t.column :audited_changes, :text
t.column :version, :bigint, default: 0
t.column :comment, :text
t.column :remote_address, :string
t.column :request_uuid, :string
t.column :created_at, :datetime
end

create_table :motor_api_configs do |t|
t.column :name, :string, null: false
t.column :url, :string, null: false
t.column :preferences, :text, null: false
t.column :credentials, :text, null: false
t.column :description, :text
t.column :deleted_at, :datetime

t.timestamps

t.index 'name',
name: 'motor_api_configs_name_unique_index',
unique: true,
where: 'deleted_at IS NULL'
end

create_table :motor_notes do |t|
t.column :body, :text
t.column :author_id, :bigint
t.column :author_type, :string
t.column :record_id, :string, null: false
t.column :record_type, :string, null: false
t.column :deleted_at, :datetime

t.timestamps

t.index %i[record_id record_type],
name: 'motor_notes_record_id_record_type_index'

t.index %i[author_id author_type],
name: 'motor_notes_author_id_author_type_index'
end

create_table :motor_note_tags do |t|
t.column :name, :string, null: false

t.timestamps

t.index 'name',
name: 'motor_note_tags_name_unique_index',
unique: true
end

create_table :motor_note_tag_tags do |t|
t.references :tag, null: false, foreign_key: { to_table: :motor_note_tags }, index: true
t.references :note, null: false, foreign_key: { to_table: :motor_notes }, index: false

t.index %i[note_id tag_id],
name: 'motor_note_tags_note_id_tag_id_index',
unique: true
end

create_table :motor_reminders do |t|
t.column :author_id, :bigint, null: false
t.column :author_type, :string, null: false
t.column :recipient_id, :bigint, null: false
t.column :recipient_type, :string, null: false
t.column :record_id, :string
t.column :record_type, :string
t.column :scheduled_at, :datetime, null: false, index: true

t.timestamps

t.index %i[author_id author_type],
name: 'motor_reminders_author_id_author_type_index'

t.index %i[recipient_id recipient_type],
name: 'motor_reminders_recipient_id_recipient_type_index'

t.index %i[record_id record_type],
name: 'motor_reminders_record_id_record_type_index'
end

create_table :motor_notifications do |t|
t.column :title, :string, null: false
t.column :description, :text
t.column :recipient_id, :bigint, null: false
t.column :recipient_type, :string, null: false
t.column :record_id, :string
t.column :record_type, :string
t.column :status, :string, null: false

t.timestamps

t.index %i[recipient_id recipient_type],
name: 'motor_notifications_recipient_id_recipient_type_index'

t.index %i[record_id record_type],
name: 'motor_notifications_record_id_record_type_index'
end

add_index :motor_audits, %i[auditable_type auditable_id version], name: 'motor_auditable_index'
add_index :motor_audits, %i[associated_type associated_id], name: 'motor_auditable_associated_index'
add_index :motor_audits, %i[user_id user_type], name: 'motor_auditable_user_index'
add_index :motor_audits, :request_uuid
add_index :motor_audits, :created_at

model = Class.new(ApplicationRecord)

model.table_name = 'motor_configs'

model.create!(key: 'header.links', value: [{
name: '⭐ Star on GitHub',
path: 'https://github.com/motor-admin/motor-admin-rails'
}].to_json)

model.table_name = 'motor_api_configs'

model.create!(name: 'origin', url: '/', preferences: {}, credentials: {})
end

def self.down
drop_table :motor_audits
drop_table :motor_alert_locks
drop_table :motor_alerts
drop_table :motor_forms
drop_table :motor_taggable_tags
drop_table :motor_tags
drop_table :motor_resources
drop_table :motor_configs
drop_table :motor_queries
drop_table :motor_dashboards
drop_table :motor_api_configs
drop_table :motor_note_tag_tags
drop_table :motor_note_tags
drop_table :motor_notes
drop_table :motor_notifications
drop_table :motor_reminders
end
end
Loading

0 comments on commit 903dd94

Please sign in to comment.