discourse/plugins/discourse-adplugin/db/migrate/20251104121941_create_house_ads_tables.rb
Juan David Martínez Cubillos cc7f4743a5
FEATURE: Implement ad impressions tracking (#35797)
**Description**

This PR implements these features:
 - Impressions tracking for HouseAds and External Ads
 - Click tracking for HouseAds and External Ads
- Reports of HouseAds performance, ad impressions by user, general ad
impressions, conversion reports by ad and placement, conversion reports
by ad type, and conversion reports by placement.

As part of implementing these features, the HouseAd model had to be
pulled out of the Plugin rows table into its own table. Refactoring had
to be done to account for these changes.

---------

Co-authored-by: Bannon Tanner <bannon.n.tanner@gmail.com>
2025-12-01 12:17:25 -05:00

50 lines
1.8 KiB
Ruby

# frozen_string_literal: true
class CreateHouseAdsTables < ActiveRecord::Migration[7.0]
def change
create_table :ad_plugin_house_ads do |t|
t.string :name, null: false
t.text :html, null: false
t.boolean :visible_to_logged_in_users, default: true, null: false
t.boolean :visible_to_anons, default: true, null: false
t.timestamps
end
create_table :ad_plugin_house_ads_groups, id: false do |t|
t.bigint :ad_plugin_house_ad_id, null: false
t.bigint :group_id, null: false
end
create_table :ad_plugin_house_ads_categories, id: false do |t|
t.bigint :ad_plugin_house_ad_id, null: false
t.bigint :category_id, null: false
end
add_foreign_key :ad_plugin_house_ads_groups,
:ad_plugin_house_ads,
column: :ad_plugin_house_ad_id,
on_delete: :cascade
add_foreign_key :ad_plugin_house_ads_groups, :groups, column: :group_id, on_delete: :cascade
add_foreign_key :ad_plugin_house_ads_categories,
:ad_plugin_house_ads,
column: :ad_plugin_house_ad_id,
on_delete: :cascade
add_foreign_key :ad_plugin_house_ads_categories,
:categories,
column: :category_id,
on_delete: :cascade
add_index :ad_plugin_house_ads, :name, unique: true
add_index :ad_plugin_house_ads, :visible_to_logged_in_users
add_index :ad_plugin_house_ads, :visible_to_anons
add_index :ad_plugin_house_ads_groups,
%i[ad_plugin_house_ad_id group_id],
name: "index_house_ads_groups"
add_index :ad_plugin_house_ads_categories,
%i[ad_plugin_house_ad_id category_id],
name: "index_house_ads_categories"
end
end