博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
heroku_Heroku Connect的美丽:简化数据库同步
阅读量:2535 次
发布时间:2019-05-11

本文共 14262 字,大约阅读时间需要 47 分钟。

heroku

by Wilson Wang

威尔逊·王(Wilson Wang)

Heroku Connect的美丽:简化数据库同步 (The Beauty of Heroku Connect: Simplifying Database Synchronization)

I’m currently a developer for , an organization at UC Berkeley. We develop software pro bono for non-profits and advance technology for social good. This past year, my team worked on building a solution for The goal is to provide a better education for children in the Dominican Republic.

我目前是UC Berkeley的组织的开发人员。 我们为公益组织开发无偿软件,并为社会公益发展先进技术。 在过去的一年中,我的团队致力于为构建解决方案 目标是为多米尼加共和国的儿童提供更好的教育。

I am writing this post in hopes of sharing my experience of doing Salesforce integration using Heroku Connect for a Ruby on Rails/React Native app.

我写这篇文章的目的是希望分享我使用Heroku Connect for Ruby on Rails / React Native应用进行Salesforce集成的经验。

什么是 ? (What is ?)

“Heroku Connect makes it easy for you to build Heroku apps that share data with your Salesforce deployment. Using bi-directional synchronization between Salesforce and Heroku Postgres, Heroku Connect unifies the data in your Postgres database with the contacts, accounts and other custom objects in the Salesforce database.”
“ Heroku Connect使您可以轻松构建与Salesforce部署共享数据的Heroku应用程序。 通过在Salesforce和Heroku Postgres之间进行双向同步,Heroku Connect可以将Postgres数据库中的数据与Salesforce数据库中的联系人,客户和其他自定义对象统一起来。”

Another way to put it…

另一种表达方式...

Heroku Connect assists with replacing your app’s Postgres database with a Salesforce database. Of course, since Rails apps connect natively to Postgres, you cannot do immediate calls and pushes to Salesforce without some API like the .

Heroku Connect可以帮助您将应用程序的Postgres数据库替换为Salesforce数据库。 当然,由于Rails应用程序本机连接到Postgres,因此如果没有诸如类的API,就无法立即调用和推送到Salesforce。

In reality, the Postgres database that our Rails app will interact with serves as a disguise for Salesforce. It is a working middleman. All data must go through it before reaching Salesforce, and vice versa. Heroku Connect is the bridge that combines the capabilities of Force.com and Heroku without the need for a gem.

实际上,我们的Rails应用程序将与之交互的Postgres数据库充当了Salesforce的伪装。 这是一个正在工作的中间人。 在到达Salesforce之前,所有数据都必须经过它,反之亦然。 Heroku Connect是将Force.com和Heroku的功能结合在一起的桥梁,而无需使用gem。

You might ask… why even bother learning Salesforce integration?

您可能会问...为什么还要麻烦学习Salesforce集成?

Well, Salesforce integration streamlines the process of storing and retrieving data. Especially customer data for businesses.

好吧,Salesforce集成简化了存储和检索数据的过程。 尤其是企业的客户数据。

You can provide your customers with modernized computer systems for an improved user experience and workflow. You’ll be accelerating app development. It also creates better tools for informing management and sales on business performance.

您可以为客户提供现代化的计算机系统,以改善用户体验和工作流程。 您将加速应用程序开发。 它还为通知管理和销售业务绩效提供了更好的工具。

This helps businesses achieve efficient levels of operation for business-to-consumer apps. It does this through instantaneous and accurate updates.

这有助于企业实现企业对消费者应用程序的有效运营水平。 它通过即时而准确的更新来实现。

灵感样本项目 (A Sample Project for Inspiration)

To give some background for the code snippets below in the tutorial, I will explain beforehand the project I was working on. This project got me introduced to Heroku Connect.

为了给本教程下面的代码片段提供一些背景知识,我将事先解释我正在从事的项目。 这个项目向我介绍了Heroku Connect。

Previously, Dream recorded student information in a Salesforce database. This was not ideal for teachers to use. To make their lives easier, we created a user-friendly app. The app handled course creation, student enrollment, and attendance taking.

以前,Dream将学生信息记录在Salesforce数据库中。 这不是教师使用的理想选择。 为了让他们的生活更轻松,我们创建了一个用户友好的应用程序。 该应用程序可以处理课程创建,学生入学和出勤等工作。

Due to the poor internet connection at Dream campuses, we turned to Heroku Connect for constant synchronization of updates. It synchronized updates on the Heroku Postgres database side and Salesforce database side.

由于Dream校园的互联网连接状况不佳,我们选择了Heroku Connect来保持同步更新。 它在Heroku Postgres数据库端和Salesforce数据库端同步更新。

All the code described in this demo is available in our . You can also check out the React side of the application .

该演示中描述的所有代码都可以在我们的 。 您也可以在签出应用程序的React端。

好吧,让我们开始演示... (Alright, let’s start the demo…)

总览 (Overview)

I’m going to tackle this demo in the following order:

我将按以下顺序处理此演示:

  1. Description of Tech

    技术说明
  2. Setup (Heroku Postgres and Heroku Connect)

    设置(Heroku Postgres和Heroku Connect)
  3. Heroku Connect Mappings + Notes

    Heroku Connect映射+注释
  4. Changes to your local Rails app

    对本地Rails应用的更改

技术说明 (Description of Tech)

  • Force.com ()

    Force.com( )

  • Rails app (my Rails version was 5.1.4)

    Rails应用程序(我的Rails版本是5.1.4)

设置:将您的应用程序部署到Rails (Setting up: Deploying your app to Rails)

After setting up your Rails app, you want to deploy your app on Heroku. Here is a quick run-through on deploying your app:

设置Rails应用程序后,您想要在Heroku上部署您的应用程序。 这是部署应用程序的快速指南:

  1. Login to your Heroku account, and you will be redirected to the dashboard on the top right. You will see a “New” button on a top right to create a new project. Type in your custom app name and create your app.

    登录到您的Heroku帐户,您将被重定向到右上角的仪表板。 您将在右上角看到一个“新建”按钮,以创建一个新项目。 输入您的自定义应用名称,然后创建您的应用。
  2. You will be redirected to the deploy page of your new app. Scroll down to the bottom to the section “Deploy using Heroku Git.” Follow the instructions on the page. (Note: after you add the Heroku Git remote you can alway update your Heroku app. You update by adding and commiting your changes and finally doing a git push heroku master.)

    您将被重定向到新应用程序的部署页面。 向下滚动到底部的“使用Heroku Git部署”部分。 请按照页面上的说明进行操作。 (注意:添加Heroku Git遥控器后,您可以始终更新您的Heroku应用。您可以通过添加并提交所做的更改并最终执行git push heroku master来进行更新。)

Most likely, if this is your first time, you will face an error: “Heroku deployment failed because of sqlite3 gem error.” This is because Heroku uses Postgres instead of sqlite3. To fix this, check out this .

如果这是您第一次,很可能会遇到错误:“由于sqlite3 gem错误,Heroku部署失败。” 这是因为Heroku使用Postgres而不是sqlite3。 要解决此问题,请查看此 。

Heroku Postgres (Heroku Postgres)

With your app deployed, your overview page should have the add-on Heroku Postgres. This is your usual database for deployed Heroku apps.

部署您的应用程序后,您的概述页面应具有加载项Heroku Postgres。 这是已部署的Heroku应用程序的常用数据库。

Click on this add-on to check the URL database info in the settings tab. Be sure to add your Postgres database URL to your Rails app.

单击此加载项以检查“设置”选项卡中的URL数据库信息。 确保将Postgres数据库URL添加到Rails应用程序中。

To add the database URL, you can either create an environment variable using the gem:

要添加数据库URL,可以使用 gem创建一个环境变量:

or just include a URL variable in your database.yml file:

或者只在您的database.yml文件中包含一个URL变量:

Heroku Connect (Heroku Connect)

Next, click on configure add-ons or the resources tab, and search for Heroku Connect. Click provision to add the add-on.

接下来,单击“配置加载项”或“资源”选项卡,然后搜索Heroku Connect。 单击“供应”以添加附件。

You will then be redirected to the screen below. Note that the schema name is “salesforce” for now (feel free to change it as well), and you’re good to continue.

然后,您将被重定向到下面的屏幕。 请注意,架构名称目前为“ salesforce”(也可以对其进行更改),您可以继续。

Click setup connection. Enter your Salesforce user info to establish the connection with the appropriate details.

单击设置连接。 输入您的Salesforce用户信息以使用适当的详细信息建立连接。

You’re now done with the setup! Now we can move on to mappings.

现在您已完成设置! 现在我们可以继续进行映射。

对应 (Mappings)

I recorded a short video of creating a mapping for a Teacher object:

我录制了一段简短的视频,该视频为Teacher对象创建映射:

The video is a walkthrough for establishing mappings. There are a couple things I want to explain further that I personally got confused with. After reading these clarifications, I would recommend rewatching the video for a better understanding.

该视频是建立映射的演练。 我想进一步解释一些我个人感到困惑的事情。 阅读这些说明后,我建议您重新观看视频以更好地理解。

1.'__c' (1. ‘__c’)

You may be asking why there are so many ‘__c’s that are appended at the end of my teacher object and teacher fields. Well, Salesforce actually appends this to each custom class/field.

您可能会问,为什么在我的教师对象和教师字段末尾附加了太多的'__c'。 好吧,Salesforce实际上将此附加到每个自定义类/字段。

So, tying back to my Rails project, the table name is now Teacher__c instead of Teacher and the columns/fields have changed from names like First_name, Last_name to First_name__c, Last_name__c. Some default fields like sfid or createddate are not custom, so they don’t require appending ‘__c’.

因此,回到我的Rails项目,表名现在改为Teacher__c而不是Teacher,并且列/字段已从诸如First_name,Last_name的名称更改为First_name__cLast_name__c 。 某些默认字段(例如sfidcreateddate)不是自定义字段,因此不需要附加“ __c”。

2.自定义字段 (2. Custom Fields)

So, how do you create custom fields? Well, there’s actually a small arrow on the right side of your screen for you to edit objects and fields.

那么,如何创建自定义字段? 好吧,实际上在屏幕的右侧有一个小箭头,供您编辑对象和字段。

After each modification, remember to check if you also need to modify your Heroku Connect mappings.

每次修改后,请记住要检查是否还需要修改Heroku Connect映射。

3.双向同步 (3. Two Way Syncing)

I wanted to point out two very cool features about Heroku Connect’s Two-Way Syncing. The first is poll frequency, which regulates how often you want your Postgres database to update with Salesforce updates. Checking the Accelerate Polling box makes most operations pretty much instantaneous.

我想指出两个有关Heroku Connect双向同步的非常酷的功能。 第一个是轮询频率,它决定了您希望Postgres数据库使用Salesforce更新进行更新的频率。 选中“加速轮询”框可以使大多数操作瞬间完成。

The second is the section on pushing data from your Postgres database to sync with the Salesforce database. You must check the box in order to have this feature work at all. However, right afterward, you will most likely see a warning pop up:

第二部分是有关从Postgres数据库推送数据以与Salesforce数据库同步的部分。 您必须选中此框才能完全使用此功能。 但是,此后,您很可能会看到警告弹出窗口:

This is a layer of protection to ensure that you don’t accidentally create duplicate objects. It’s great if you have a unique identifier (in the video, each teacher has a unique email, so I made that my identifier). Otherwise, you can skip it and still have a functional Heroku Connect mapping. However, you may want to program your app to double check for existing records before creating an object.

这是一层保护,可确保您不会意外创建重复的对象。 如果您有一个唯一的标识符,那就太好了(在视频中,每个老师都有一个唯一的电子邮件,因此我将其作为标识符)。 否则,您可以跳过它,但仍具有功能良好的Heroku Connect映射。 但是,您可能希望对应用进行编程,以在创建对象之前仔细检查现有记录。

对本地Rails应用的更改 (Changes to your local Rails app)

Now that you have your Heroku Connect all nice and set up, it’s time for a quick local adjustment before you can interact with your Salesforce data.

现在,您已经很好地设置了Heroku Connect,并进行设置,是时候进行快速本地调整,然后才能与Salesforce数据进行交互。

In overview, you will see the name of your schema, in this case “salesforce”. If you had picked a different name during the provisioning phase, that name would show up here instead.

在概述中,您将看到架构的名称,在本例中为“ salesforce”。 如果您在配置阶段选择了其他名称,则该名称将显示在此处。

Because my Rails app’s table name is still Teacher, I need to change it to Teacher__c to correctly reference the Salesforce data. I must change the table name to the format schema_name.object_name or salesforce.teacher__c to reflect the changes.

因为我的Rails应用程序的表名仍然是Teacher,所以我需要将其更改为Teacher__c才能正确引用Salesforce数据。 我必须将表名更改为schema_name格式。 object_namesalesforce.teacher__c以反映更改。

The other notable change applies if your model has validated statements, like my Teacher model. Following the validates keyword, we still have the old field names like first_name without ‘__c’ and last_name without ‘__c’. We need to change those names by either appending the ‘__c’ to the old field names or by creating separate methods:

如果您的模型具有经过验证的语句(如“我的老师”模型),则适用另一个显着更改。 在validates关键字之后,我们仍然具有旧的字段名称,例如first_name(不带'__c')和last_name(不带'__c')。 我们需要通过在旧字段名称后附加'__c'或创建单独的方法来更改这些名称:

Afterwards, create some objects in Salesforce and open up your Rails console to retrieve this info. (In the video, I called Teacher.all to display all Salesforce Teacher objects in my Rails console.) The information should also be reflected in the Heroku Connect explorer.

然后,在Salesforce中创建一些对象并打开Rails控制台以检索此信息。 (在视频中,我调用了Teacher.all在我的Rails控制台中显示了所有Salesforce Teacher对象。)这些信息也应该反映在Heroku Connect资源管理器中。

反射 (Reflection)

I spent a good half of my semester trying to figure out Salesforce integration. I did lots of research, experimented with different solutions, and plenty of support. In the end, it was a very enlightening experience to work with the cool features of Salesforce/Heroku/Rails. I also learned how much I’ve grown as a developer and reflect on my strengths and weaknesses.

我花了整个学期的一半时间来弄清楚Salesforce的集成。 我做了很多研究,尝试了不同的解决方案,并提供了很多支持。 最后,使用Salesforce / Heroku / Rails的出色功能带来了非常令人启发的体验。 我还了解了自己作为一名开发人员已经成长了多少,并反思了自己的长处和短处。

Usually people implement the first solutions they find. They do this without understanding why it is good or bad. I researched and planned out three separate solutions before discovering Heroku Connect. Through this, I realized how important it was to weigh the pros and cons of different solutions before settling, even if more time is spent researching instead of implementing.

通常人们会实施他们找到的第一个解决方案。 他们这样做时并不了解它的好坏。 在发现Heroku Connect之前,我研究并计划了三种单独的解决方案。 通过这一点,我意识到,在解决之前,权衡不同解决方案的利弊是多么重要,即使花费更多的时间来研究而不是执行。

By using this knowledge, my team and I built an app to help teachers provide quality education for students in the Dominican Republic schools that have a poor connection to the Internet. We learned to persevere when times were hard because we knew that despite every long work session, every bug fix, every line of code, we had a mission, and every step of the way was another step towards improving the world.

通过使用这些知识,我和我的团队构建了一个应用程序,以帮助教师为多米尼加共和国学校中与互联网连接较差的学生提供优质的教育。 在艰难的时刻,我们学会了坚持不懈,因为我们知道,尽管每次工作很长时间,每一个错误修复,每一行代码,我们都有使命,而每一步都是迈向改善世界的又一步。

This experience helped me to really prioritize the goal and the importance of doing quality work instead of immediately using the fastest way to go. Every solution is worth researching its pros and cons. It’s all about resilience and tenacity.

这种经验帮助我真正确定了目标和进行高质量工作的重要性,而不是立即使用最快的方法。 每个解决方案都值得研究其优缺点。 一切都与韧性和韧性有关。

So to all developers out there, no matter what situation you’re in, don’t give up. Don’t be afraid of trying new solutions and failing. Stay positive and Happy Deving!

因此,对于所有开发人员,无论您处于什么情况,都不要放弃。 不要害怕尝试新的解决方案而失败。 保持积极乐观的态度!

Wilson Wang is a junior at UC Berkeley studying computer science and data science. He is interested in developing software for improving business-customer relationships. Besides technology, Wilson is passionate about martial arts, architectural design, and landscape photography.

Wilson Wang是加州大学伯克利分校的大三学生,学习计算机科学和数据科学。 他对开发用于改善业务与客户关系的软件感兴趣。 除了技术之外,威尔逊还热衷于武术,建筑设计和风景摄影。

谢谢阅读! 要了解有关Blueprint的更多信息,请在和关注我们,并访问我们的 ! (Thanks for reading! To learn more about Blueprint, follow us on and , and visit our !)

翻译自:

heroku

转载地址:http://pcewd.baihongyu.com/

你可能感兴趣的文章
2014年军训总结
查看>>
扩展 -------jQuery
查看>>
Winform跨线程操作最简单的办法
查看>>
[51nod1532]带可选字符的多字符串匹配
查看>>
socket 基于udp实现远程执行命令
查看>>
读取本地json文件,解析json
查看>>
【学习】循环语句1027
查看>>
Git提交代码报错Git push error:src refspec XXX matches more than one解决方案
查看>>
软件设计规格说明书
查看>>
bzoj 1500: [NOI2005]维修数列 -- splay
查看>>
设计模式 - 简单工厂
查看>>
数组与指针杂记
查看>>
四色原理
查看>>
Codeforces Round#500 Div.2 翻车记
查看>>
再更新ww的mingw MinGW-full-20101119
查看>>
Benefit UVA - 11889
查看>>
全排列 最详细的解题报告
查看>>
c++ web服务器
查看>>
android机型排行榜(201509)
查看>>
eclipse + maven + scala+spark环境搭建
查看>>