INSERT INTO itgr.sf_object (tenant_id, sf_object_name, for_sync) VALUES 
(1, 'Account', false),
(1, 'Product2', false),
(1, 'ContentDocument', false),
(1, 'ContentVersion', false),
(1, 'RecordType', true)
ON CONFLICT (tenant_id, sf_object_name) 
DO NOTHING;

INSERT INTO itgr.sf_object_field (tenant_id, sf_object_id, sf_field_name, is_active) VALUES
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'Id', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'IsDeleted', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'Name', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'Type', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'RecordTypeId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'LastModifiedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'LastModifiedDate', true)
ON CONFLICT (tenant_id, sf_object_id, sf_field_name) 
DO UPDATE 
SET is_active = TRUE;

INSERT INTO itgr.sf_object_field (tenant_id, sf_object_id, sf_field_name, is_active) VALUES
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'Id', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'Name', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'ProductCode', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'Description', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'IsActive', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'IsArchived', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'CreatedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'CreatedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'LastModifiedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'LastModifiedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'RecordTypeId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'IsDeleted', true)
ON CONFLICT (tenant_id, sf_object_id, sf_field_name) 
DO UPDATE 
SET is_active = TRUE;

INSERT INTO itgr.sf_object_field (tenant_id, sf_object_id, sf_field_name, is_active) VALUES
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ArchivedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ArchivedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ContentAssetId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ContentModifiedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ContentSize', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'CreatedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'CreatedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'Description', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'FileExtension', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'FileType', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'Id', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'IsArchived', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'IsDeleted', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'LastModifiedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'LastModifiedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'LastReferencedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'LastViewedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'LatestPublishedVersionId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'OwnerId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ParentId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'PublishStatus', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'SharingOption', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'SharingPrivacy', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'SystemModstamp', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'Title', true)
ON CONFLICT (tenant_id, sf_object_id, sf_field_name) 
DO UPDATE 
SET is_active = TRUE;

INSERT INTO itgr.sf_object_field (tenant_id, sf_object_id, sf_field_name, is_active) VALUES
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'Checksum', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentBodyId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentDocumentId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentLocation', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentModifiedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentModifiedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentSize', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentUrl', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'CreatedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'CreatedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'Description', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ExternalDataSourceId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ExternalDocumentInfo1', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ExternalDocumentInfo2', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'FeaturedContentBoost', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'FeaturedContentDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'FileExtension', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'FileType', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'FirstPublishLocationId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'Id', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'IsAssetEnabled', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'IsDeleted', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'IsLatest', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'IsMajorVersion', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'LastModifiedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'LastModifiedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'NegativeRatingCount', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'NetworkId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'Origin', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'OwnerId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'PathOnClient', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'PositiveRatingCount', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'PublishStatus', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'RatingCount', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ReasonForChange', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'SharingOption', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'SharingPrivacy', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'SystemModstamp', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'TagCsv', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'TextPreview', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'Title', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'VersionData', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'VersionNumber', true)
ON CONFLICT (tenant_id, sf_object_id, sf_field_name) 
DO UPDATE 
SET is_active = TRUE;

INSERT INTO itgr.sf_object_field (tenant_id, sf_object_id, sf_field_name, is_active) VALUES
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'BusinessProcessId', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'CreatedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'CreatedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'Description', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'DeveloperName', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'Id', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'IsActive', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'IsPersonType', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'LastModifiedById', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'LastModifiedDate', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'Name', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'NamespacePrefix', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'SobjectType', true),
(1, (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'SystemModstamp', true)
ON CONFLICT (tenant_id, sf_object_id, sf_field_name) 
DO UPDATE 
SET is_active = TRUE;

INSERT INTO itgr."schema" (tenant_id, name, description, type) VALUES 
(1, 'all_documents', '', 'inbound')
ON CONFLICT (tenant_id, name, type)
DO NOTHING;

INSERT INTO itgr."schema_object" (tenant_id, schema_id, sf_object_id, sf_object_name, filter, is_active) VALUES 
(1, (SELECT id FROM itgr."schema" WHERE name = 'all_documents'), (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Account'), 'Account', NULL, TRUE),
(1, (SELECT id FROM itgr."schema" WHERE name = 'all_documents'), (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'Product2'), 'Product2', NULL, TRUE),
(1, (SELECT id FROM itgr."schema" WHERE name = 'all_documents'), (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentDocument'), 'ContentDocument', NULL, TRUE),
(1, (SELECT id FROM itgr."schema" WHERE name = 'all_documents'), (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'ContentVersion'), 'ContentVersion', NULL, TRUE),
(1, (SELECT id FROM itgr."schema" WHERE name = 'all_documents'), (SELECT id FROM itgr.sf_object WHERE sf_object_name = 'RecordType'), 'RecordType', NULL, TRUE)
ON CONFLICT (tenant_id, schema_id, sf_object_id) 
DO NOTHING;