Add neighborhood airtable post records

This commit is contained in:
Max Wofford
2025-05-16 10:04:02 -04:00
parent 6a3c3a2f26
commit ee3beb0506
4 changed files with 51 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
module HasTableSync
extend ActiveSupport::Concern
validates :airtable_fields, presence: true
validates :airtable_id, presence: true, uniqueness: true
class_methods do
def has_table_sync(pat:, base:, table:)
@table_sync_pat = pat
@table_sync_base = base
@table_sync_table = table
@table = Norairrecord.table(pat, base, table)
def pull_all_from_airtable!
records = @table.all
records.each do |record|
find_or_initialize_by(airtable_id: record.id).update(airtable_fields: record.fields)
end
end
end
end
end

View File

@@ -0,0 +1,7 @@
class Neighborhood::Post < ApplicationRecord
include HasTableSync
has_table_sync base: "appnsN4MzbnfMY0ai",
table: "tbl0iKxglbySiEbB4",
pat: ENV["NEIGHBORHOOD_AIRTABLE_PAT"]
end

View File

@@ -0,0 +1,11 @@
class CreateNeighborhoodPosts < ActiveRecord::Migration[8.0]
def change
create_table :neighborhood_posts do |t|
t.string :airtable_id, null: false
t.index :airtable_id, unique: true
t.jsonb :airtable_fields
t.timestamps
end
end
end

10
db/schema.rb generated
View File

@@ -10,9 +10,9 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_05_14_212714) do
create_schema "pganalyze"
ActiveRecord::Schema[8.0].define(version: 2025_05_16_140014) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"
enable_extension "pg_stat_statements"
@@ -264,6 +264,14 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_14_212714) do
t.index ["user_id"], name: "index_mailing_addresses_on_user_id"
end
create_table "neighborhood_posts", force: :cascade do |t|
t.string "airtable_id", null: false
t.jsonb "airtable_fields"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["airtable_id"], name: "index_neighborhood_posts_on_airtable_id", unique: true
end
create_table "physical_mails", force: :cascade do |t|
t.bigint "user_id", null: false
t.integer "mission_type", null: false