<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>stevefan (emrysfan)</title>
    <link>https://ruby-china.org/stevefan</link>
    <description></description>
    <language>en-us</language>
    <item>
      <title>用 Elixir &amp; Phoenix 撸了个站点 - Product Dunk</title>
      <description>&lt;p&gt;学以致用，学了 Elixir 就做个项目练练手 &lt;a href="https://productdunk.com" rel="nofollow" target="_blank" title=""&gt;ProductDunk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Product Dunk 模仿的是大名鼎鼎的 Product Hunt，用来发布独立小产品以及给 Maker 提交交流的平台。&lt;/p&gt;

&lt;p&gt;关于技术，后端 Phoenix Framework，前端 React，使用了 create-react-app 脚手架，分离前后端，富文本编辑使用了 BaseCamp 开源的 Trix。&lt;/p&gt;

&lt;p&gt;关于部署，接 git clone 到服务器，在服务器上 mix release 打包。主要是用过 remote_console 之后，发现小站点在服务器上直接 hot fix 很方便，风险也不高。
之前的项目采用的是在本地 Docker 环境打包，然后部署到远程服务器，没这么省心。&lt;/p&gt;

&lt;p&gt;👏欢迎提建议和反馈！&lt;/p&gt;

&lt;p&gt;最后上图&lt;/p&gt;

&lt;p&gt;&lt;img src="https://l.ruby-china.com/photo/2019/de13e0b9-5179-4668-8062-bd5442e64263.png!large" title="" alt=""&gt;
&lt;img src="https://l.ruby-china.com/photo/2019/c6b14b0e-8f4c-456b-a194-fc54413f1a2e.png!large" title="" alt=""&gt;
&lt;img src="https://l.ruby-china.com/photo/2019/ad94b288-5bc7-4fa4-aaf1-5d530ad56b43.jpeg!large" width="300px" alt=""&gt;
&lt;img src="https://l.ruby-china.com/photo/2019/5a88ac03-fb83-4a43-83f1-11987128992b.jpeg!large" width="300px" alt=""&gt;&lt;/p&gt;

&lt;p&gt;附上链接  &lt;a href="https://productdunk.com" rel="nofollow" target="_blank" title=""&gt;ProductDunk&lt;/a&gt;&lt;/p&gt;</description>
      <author>stevefan</author>
      <pubDate>Mon, 16 Dec 2019 09:39:32 +0800</pubDate>
      <link>https://ruby-china.org/topics/39338</link>
      <guid>https://ruby-china.org/topics/39338</guid>
    </item>
    <item>
      <title>关于生产环境数据库迁移正确姿势的问题</title>
      <description>&lt;h3 id="需求描述"&gt;需求描述&lt;/h3&gt;
&lt;p&gt;目前有一张表（clients）中，想把该表的一个字段（title）分离出来，新建一张表（programs），programs 表中包含 title 字段，然后在 clients 表中添加 program_id 外键。&lt;/p&gt;
&lt;h3 id="数据库模式迁移："&gt;数据库模式迁移：&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;新建 program model，（&lt;code&gt;rails g model program title:string&lt;/code&gt;）&lt;/li&gt;
&lt;li&gt;添加外键 program_id 到 clients， （&lt;code&gt;add_references :clients, :program&lt;/code&gt;）&lt;/li&gt;
&lt;li&gt;删除 clients 表中的 ttile 字段，（&lt;code&gt;remove_column :clients, :title&lt;/code&gt;）&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="问题"&gt;问题&lt;/h3&gt;
&lt;p&gt;问题在于，在生成环境中，这张表已经有大量数据存在，如果直接 &lt;code&gt;db:migrate&lt;/code&gt; 估计 clients 表中的 title 字段的数据会全部丢失。&lt;/p&gt;
&lt;h3 id="我的解决方案"&gt;我的解决方案&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;添加 rake task，根据 Client.select(:title).distinct 的查询结果，填充 program 记录。&lt;/li&gt;
&lt;li&gt;在数据库模式迁移过程的第一步后执行上述 rake task。&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="请教"&gt;请教&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;不知该姿势是否正确？&lt;/li&gt;
&lt;li&gt;其他更好的姿势？&lt;/li&gt;
&lt;/ul&gt;</description>
      <author>stevefan</author>
      <pubDate>Mon, 25 May 2015 17:54:24 +0800</pubDate>
      <link>https://ruby-china.org/topics/25736</link>
      <guid>https://ruby-china.org/topics/25736</guid>
    </item>
  </channel>
</rss>
