Skip to content

Instantly share code, notes, and snippets.

View rlburkes's full-sized avatar

Randy Burkes rlburkes

View GitHub Profile
class ProductAttribute < ActiveRecord::Base
include DiscriminableModel
uses_type_column :data_type do |data_type|
"#{data_type.to_s.camelize}ProductAttribute".safe_constantize
end
...
end
{
"id": "{SYSTEM_ID}",
"parent_id": "{PARENT_SYSTEM_ID}",
"product_type": [ "leaf" ],
"updated_at": "2016-04-07T12:52:03.059Z",
"indexed_at": "2016-04-07T13:29:54.262+00:00",
"created_at": "2016-04-07T13:29:54.262+00:00",
"list_membership": [
"{SYSTEM_ID}"
],
@rlburkes
rlburkes / foo.sql
Created February 17, 2018 21:21
Crazy Migration
CREATE TRIGGER migrate_products AFTER UPDATE OF migrated ON products FOR EACH ROW WHEN (OLD.migrated IS NULL AND NEW.migrated IS true) EXECUTE PROCEDURE populate_referenced_entities();
CREATE OR REPLACE FUNCTION batch_set_migrated() RETURNS INTEGER LANGUAGE plpgsql AS $$
DECLARE batched_count INTEGER = 1;
BEGIN
WITH unmigrated_products AS (
SELECT id
FROM products
WHERE migrated IS NULL
LIMIT 50