LINE Front-end Framework(LIFF)でアプリケーションを開発したい - 5日目

昨日で「LINE公式アカウントのトーク画面からLIFFスターターアプリの画面を開く」ところまでできました。本日からサーバ側の開発を進めます。

PostgreSQLのインストール

検索すればいくらでも手順が出てきますが、一応残しておきます。

$ brew install postgresql
Updating Homebrew...
==> Auto-updated Homebrew!
...(略)...
Or, if you don't want/need a background service you can just run:
 pg_ctl -D /usr/local/var/postgres start
$ psql --version
psql (PostgreSQL) 12.2

参考にしたサイトでは、このあと「initdb」でデータベースを初期化となっていましたが、実行すると「initdb: error: directory "/usr/local/var/postgres" exists but is not empty〜」というエラーとなりました。どうやらインストール時に初期化が終わっているようですので、そのまま進めました。

$ brew services start postgresql
==> Tapping homebrew/services
...(略)...
​==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
$ psql -l
   Name    |  Owner  | Encoding | Collate | Ctype |  Access privileges  
-----------+---------+----------+---------+-------+---------------------
postgres  | xxxxxxx | UTF8     | C       | C     | 
template0 | xxxxxxx | UTF8     | C       | C     | =c/xxxxxxx         +
          |         |          |         |       | xxxxxxx=CTc/xxxxxxx
template1 | xxxxxxx | UTF8     | C       | C     | =c/xxxxxxx         +
          |         |          |         |       | xxxxxxx=CTc/xxxxxxx

開発用データベースを作成します。

$ createdb develop
$ psql -l
                          List of databases
  Name    |  Owner  | Encoding | Collate | Ctype |  Access privileges  
-----------+---------+----------+---------+-------+---------------------
develop   | xxxxxxx | UTF8     | C       | C     | 
postgres  | xxxxxxx | UTF8     | C       | C     | 
template0 | xxxxxxx | UTF8     | C       | C     | =c/xxxxxxx         +
          |         |          |         |       | xxxxxxx=CTc/xxxxxxx
template1 | xxxxxxx | UTF8     | C       | C     | =c/xxxxxxx         +
          |         |          |         |       | xxxxxxx=CTc/xxxxxxx

テーブル作成

作成したデータベースに、以下のテーブルを作成します。

マスタテーブル:m_facility(施設)
・facility_id(施設ID:主キー)
・name(施設名)
・picture(施設の写真のファイルパス)
トランザクションテーブル:t_reservation(予約)
・facility_id(施設ID)
・reservation_date(予約日)
・user_id(LINE Platformから取得したUser ID)
$ psql develop
psql (12.2)
Type "help" for help.

develop=# create table m_facility (
develop(# facility_id int,
develop(# name text,
develop(# picture text,
develop(# primary key(facility_id));
CREATE TABLE

develop=# create table t_reservation (
develop(# facility_id int,
develop(# reservation_date date,
develop(# user_id text);
CREATE TABLE

施設テーブルにテストデータを追加します。

develop=# insert into m_facility(facility_id, name, picture) values (1, '会議室1', '001.jpg');
INSERT 0 1
develop=# insert into m_facility(facility_id, name, picture) values (2, '会議室2', '002.jpg');
INSERT 0 1
develop=# insert into m_facility(facility_id, name, picture) values (3, '会議室3', '003.jpg');
INSERT 0 1
develop=# insert into m_facility(facility_id, name, picture) values (4, 'ホールA', '004.jpg');
INSERT 0 1
develop=# insert into m_facility(facility_id, name, picture) values (5, 'ホールB', '005.jpg');
INSERT 0 1

develop=# select * from m_facility;
facility_id |  name   | picture 
-------------+---------+---------
          1 | 会議室1 | 001.jpg
          2 | 会議室2 | 002.jpg
          3 | 会議室3 | 003.jpg
          4 | ホールA | 004.jpg
          5 | ホールB | 005.jpg
(5 rows)

本日はここまで!

この記事が気に入ったらサポートをしてみませんか?