前回までの作業で,
データベース設計とテーブル定義
データベースのテーブルを作成するためには,
画面 | フィールド1 | フィールド2 |
---|---|---|
新規エントリー入力画面 | タイトル | 内容 |
新規エントリー入力確認画面 | タイトル | 内容 |
エントリー一覧画面 | タイトル | |
エントリー参照画面 | タイトル | 内容 |
エントリー編集画面 | タイトル | 内容 |
エントリー削除確認画面 | タイトル | 内容 |
ごらんの通り,
/path/
CREATE TABLE entry (
id serial,
title varchar(255) NOT NULL,
content text NOT NULL,
PRIMARY KEY(id)
);
データベース及びユーザの作成
次に,
pgbashによるデータベース及びユーザの作成
> connect to template1@localhost user postgres password; # PostgreSQL 8.2.1 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.4 (mingw special) # CONNECT TO template1@localhost:5432 AS template1 USER postgres > create user pieceblog with password 'pieceblog'; CREATE ROLE > ?u [ List of user names ] Username | SupperUser | CreateDB ------------------+------------+---------- postgres | yes | yes pieceblog | no | no (2 rows)
> create database pieceblog owner pieceblog encoding 'UTF8'; CREATE DATABASE > ?l [ List of databases ] Name | Owner | Encoding ------------------+------------------+---------- pieceblog | pieceblog | UTF8 postgres | postgres | EUC_JP template0 | postgres | EUC_JP template1 | postgres | EUC_JP (4 rows)
作成が完了したら,
pgbashによる接続のテスト
> connect to pieceblog@localhost user pieceblog pieceblog; # PostgreSQL 8.2.1 on i686-pc-mingw32, compiled by GCC gcc.exe (GCC) 3.4.4 (mingw special) # CONNECT TO pieceblog@localhost:5432 AS pieceblog USER pieceblog > ?m # Connected Databases List (C: current database is '*') +---+--------------+-----------+---------------------------+-----------------+ | C | connect_name | user_name | target_name(db@host:port) | client_encoding | +---+--------------+-----------+---------------------------+-----------------+ | | template1 | postgres | template1@localhost:5432 | | | * | pieceblog | pieceblog | pieceblog@localhost:5432 | | +---+--------------+-----------+---------------------------+-----------------+ (2 rows)
テーブルの作成
続いて,
pgbashによるテーブルの作成
> CREATE TABLE entry ( > id serial, > title varchar(255) NOT NULL, > content text NOT NULL, > PRIMARY KEY(id) > ); NOTICE: CREATE TABLE will create implicit sequence "entry_id_seq" for serial column "entry.id" NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "entry_pkey" for table "entry" CREATE TABLE > ?d entry [ "entry" data definitions ] Attribute | Type | NotNull | Default -----------+------------------------+----------+----------------------------------- id | integer | not null | nextval('entry_id_seq'::regclass) title | character varying(255) | not null | content | text | not null | (3 rows) PrimaryKey: entry_pkey
以上でデータベース側の準備は完了です。