heroku

by Wilson Wang

威尔逊·王(Wilson Wang)

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

I’m currently a developer for Blueprint, 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 Dream Project. The goal is to provide a better education for children in the Dominican Republic.

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

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集成的经验。

什么是Heroku Connect ? (What is Heroku Connect?)

“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 Restforce gem.

Heroku Connect可以帮助您将应用程序的Postgres数据库替换为Salesforce数据库。 当然,由于Rails应用程序本机连接到Postgres,因此如果没有诸如Restforce gem之类的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 project repo. You can also check out the React side of the application here.

该演示中描述的所有代码都可以在我们的项目仓库中找到 。 您也可以在此处签出应用程序的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 + NotesHeroku Connect映射+注释
  4. Changes to your local Rails app对本地Rails应用的更改

技术说明 (Description of Tech)

  • Force.com (Salesforce Developer Account)

    Force.com( Salesforce开发人员帐户 )

  • Heroku Connect

    Heroku Connect

  • 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 Stack Overflow post.

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

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 Figaro gem:

要添加数据库URL,可以使用Figaro 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的更多信息,请在Facebook和Instagram上关注我们,并访问我们的网站 ! (Thanks for reading! To learn more about Blueprint, follow us on Facebook and Instagram, and visit our website!)

翻译自: https://www.freecodecamp.org/news/the-beauty-of-heroku-connect-simplifying-database-synchronization-e57451d3b376/

heroku

heroku_Heroku Connect的美丽:简化数据库同步相关推荐

  1. mysql5.5分别把这两个数据库同步到不同的从服务器

    2019独角兽企业重金招聘Python工程师标准>>> 一个主库上有2个数据库,分别把这两个数据库同步到不同的从服务器 需要注意的是:若使用基于语句的或混合类型的复制,则此处不能使用 ...

  2. 通过SQL Server 2008数据库复制实现数据库同步备份

    通过SQL Server 2008数据库复制实现数据库同步备份 原文 通过SQL Server 2008数据库复制实现数据库同步备份 SQL Server 2008数据库复制是通过发布/订阅的机制进行 ...

  3. PG数据库同步数据到ES数据库

    思想   ES数据库同步PG数据库在本文主要用到的思想是:在PG数据库的数据录入以及更新时,如下图所示,会有其对应的字段modify_time记录最后的修改时间.程序会记录同步到ES数据库中最后一条数 ...

  4. Qt数据库应用15-通用数据库同步

    一.前言 数据库同步的主要功能是将本地的数据库记录同步到远程的数据库,其中数据库类型不限,比如本地是sqlite数据库,远程可以是mysql数据库,本地是mysql数据库,远程也可以是postgres ...

  5. 记一次阿里云RDS与自建数据库同步中断的补救过程

    背景 2018年4月24日上午9点左右,小编在即将托管的服务器上建立数据库,并通过openvpn建立加密隧道,从而实现阿里云RDS和本地自建数据库之间同步.在托管服务器上配置openvpn后,重启op ...

  6. MySQL主从数据库同步延迟问题解决

    MySQL主从数据库同步延迟问题 摘要: MySQL的主从同步是一个很成熟的架构,优点为:①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力;②在从主服务器进行备份,避免备份期间影响 ...

  7. DataUml Design 教程3-模型与数据库同步

    上一节我们已经建立好了数据模型,那么怎么让数据模型和数据库进行同步呢?模型同步到数据库非常简单,只需要模型绑定到数据库即可.DataUml Design目前支持和Oracle与MS Server数据库 ...

  8. SQL SERVER 2008 利用发布订阅方式实现数据库同步

    数据库同步方式有很多种,这里以SQL Server 2008 为例利用数据库发布和订阅的方式来演示数据库的同步技术.由于就有一台计算机,只能在同一个服务器下两个不同的数据库之间进行数据同步进行演示. ...

  9. SQL Server主从数据库同步方式及同步问题解决方案总结

    SQL Server主从数据库同步方式及同步问题解决方案总结 参考文章: (1)SQL Server主从数据库同步方式及同步问题解决方案总结 (2)https://www.cnblogs.com/zh ...

最新文章

  1. 某程序员女友爆料:男朋友和公司的UI搞到了一起!女UI段位太高!半夜公然打电话挑衅!
  2. TEMPO研究第一年影像学数据: 骨侵蚀修复几乎只出现在无关节肿胀或肿胀改善组...
  3. Python Django 自定义Manager实现批量删除(逻辑删除)
  4. 网络OSI和TCP/IP参考模型
  5. 消息队列中数据丢失了怎么办
  6. jupyter中保存图片_露哥的摸爬滚打| Jupyter从零开始
  7. 机器学习笔记(十四)——HMM估计问题和前向后向算法
  8. arm-none-eabi-gcc.exe -v
  9. 一篇非常有用的文章-《台湾清华彭明辉教授的研究生手册》如何发现一个研究课题?
  10. ide循环执行用例 selenium_使用Selenium测试Web界面时使用循环控制功能
  11. 【联合仿真】Adams六关节机械臂与Matlab/Simulink的联合仿真(上)
  12. php5.6软件下载,【PHP下载】PHP for Linux 5.6.6-ZOL软件下载
  13. 郭天祥老师单片机教程之串口练习题
  14. Python实现快速大文件比较代码解析
  15. 虚拟机架设服务器u盘不显示盘符,【图文详解】怎么解决win7虚拟机无法识别U盘问题...
  16. 【Java】线程插队
  17. 国际标准智商测试题答案
  18. Latex中使用thebibliography环境时去除“参考文献”标题方法
  19. [ECE]模拟试题-4
  20. 【drag】HTML5 drag API

热门文章

  1. Kubernetes-命名空间namespace(ns)(十四)
  2. java演练 猜奇偶小游戏开发 DB游戏必输的设计
  3. qdir安装 多窗口资源管理软件
  4. 16-mysql-dml语言-增删改数据
  5. python-函数的返回值
  6. django-中间件,视图函数调用前会执行的
  7. linux-vim-文本编辑
  8. bootstrap-模态框
  9. Last_Errno: 1755 Last_Error: Cannot execute the current event group in the parallel mode错误解决
  10. MySQL删除重复数据保留1条