最新版 |
編集中の文章 |
27行目: |
27行目: |
| ==== Users ==== | | ==== Users ==== |
| * はじめにtepnoteのユーザーをエクスポートし tep3にインポートする | | * はじめにtepnoteのユーザーをエクスポートし tep3にインポートする |
− | ==== Notes ==== | + | ==== Jiins → Notes ==== |
| * tepnoteのjiinsをエクスポートし tep3のnotesにインポートする | | * tepnoteのjiinsをエクスポートし tep3のnotesにインポートする |
| <pre> | | <pre> |
38行目: |
38行目: |
| </pre> | | </pre> |
| :- このときJiinsのidとNotesのidを合わせる Notesのuser_idは1にする(1は淨久寺グループが代々引き継ぐアカウントのユーザーID) | | :- このときJiinsのidとNotesのidを合わせる Notesのuser_idは1にする(1は淨久寺グループが代々引き継ぐアカウントのユーザーID) |
− | <pre>
| |
− | update notes set user_id = 1;
| |
− | </pre>
| |
| <pre> | | <pre> |
| tep3_development=# select * from notes; | | tep3_development=# select * from notes; |
62行目: |
59行目: |
| </pre> | | </pre> |
| | | |
− | ==== Clients ==== | + | ==== ClientsをClientsとOthersに分ける ==== |
− | * 旧ClientsをClientsとOthersに分ける 寺ごと(ノートごと)に出し入れする | + | * 新Clients(家テーブル) 旧Clientsから主を抜き出す ie_idを新Clientsのidにする そのidにOthersがぶらさがる 旧Clientsのmemoは別テーブルに移す |
− | :- 新Clients(家テーブル) 旧Clientsから主を抜き出す ie_idを新Clientsのidにする そのidにOthersがぶらさがる 旧Clientsのmemoは別テーブルに移す | + | :- 今回はスキーマを変更したので寺ごとに出し入れする |
| <pre> | | <pre> |
| エクスポート | | エクスポート |
− | \COPY (select ie_id, user_id, jiin_id, table_order, created_at, updated_at from clients where jiin_id = 1 and nusi = true order by ie_id asc, jiin_id asc) TO '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER; | + | \COPY (select ie_id, user_id, jiin_id, created_at, updated_at from clients where jiin_id = 1 and nusi = true order by ie_id asc, jiin_id asc) TO '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER; |
| | | |
− | \COPY (select ie_id, user_id, jiin_id, table_order, created_at, updated_at from clients where jiin_id = 2 and nusi = true order by ie_id asc, jiin_id asc) TO '/Users/jq/3tep_gomi/clients_2.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER; | + | \COPY (select ie_id, user_id, jiin_id, created_at, updated_at from clients where jiin_id = 2 and nusi = true order by ie_id asc, jiin_id asc) TO '/Users/jq/3tep_gomi/clients_2.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER; |
| | | |
| ... | | ... |
75行目: |
72行目: |
| <pre> | | <pre> |
| インポート | | インポート |
− | \COPY clients(id, user_id, note_id, line, created_at, updated_at) FROM '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ','; | + | \COPY clients(id, user_id, note_id, created_at, updated_at) FROM '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ','; |
| | | |
− | \COPY clients(id, user_id, note_id, line, created_at, updated_at) FROM '/Users/jq/3tep_gomi/clients_2.csv' WITH CSV DELIMITER ','; | + | \COPY clients(id, user_id, note_id, created_at, updated_at) FROM '/Users/jq/3tep_gomi/clients_2.csv' WITH CSV DELIMITER ','; |
| | | |
| ... | | ... |
| </pre> | | </pre> |
− | :- シーケンス編集
| + | * Others |
− | <pre>
| |
− | シーケンスの最大値確認
| |
− | select max(id) from clients;
| |
− | | |
− | シーケンスを最大値以上に設定
| |
− | select setval ('clients_id_seq', 5128);
| |
− | </pre>
| |
− | :- list_idにnullがあるとき
| |
− | <pre>
| |
− | リスト「未分類」を作りそのidを入れる
| |
− | update clients set list_id = 102 where list_id is null;
| |
− | </pre>
| |
− | | |
− | ==== Others ====
| |
− | * 旧ClientsをClientsとOthersに分ける 寺ごと(ノートごと)に出し入れする
| |
| <pre> | | <pre> |
| エクスポート | | エクスポート |
− | \COPY (select user_id, jiin_id, ie_id, name, yomi, nusi, each_order, generation, created_at, updated_at from clients where jiin_id = 1 order by ie_id asc) TO '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER; | + | \COPY (select user_id, jiin_id, ie_id, name, yomi, nusi, each_order, table_order, generation, created_at, updated_at from clients where jiin_id = 1 order by ie_id asc) TO '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER; |
| | | |
| ... | | ... |
105行目: |
87行目: |
| <pre> | | <pre> |
| インポート | | インポート |
− | \COPY others(user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ','; | + | \COPY others(user_id, note_id, client_id, name, yomi, nusi, line1, line2, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ','; |
| | | |
| ... | | ... |
| </pre> | | </pre> |
| | | |
− | ==== おまけ ==== | + | ==== Categories → Lists ==== |
− | * エラー
| |
− | :- Othersのclient_idがClientsのidにないとき
| |
− | <pre>
| |
− | ERROR: insert or update on table "others" violates foreign key constraint "fk_rails_10377da6e2"
| |
− | DETAIL: Key (client_id)=(26) is not present in table "clients".
| |
− | </pre>
| |
− | :- others_1.csvから不要なclient_idを含む行の削除方法
| |
− | <pre>
| |
− | 作業用データベースを作る
| |
− | % psql postgres
| |
− | postgres=# create database x_0226;
| |
− | | |
− | 作業用テーブルを作る
| |
− | % psql x_0226
| |
− | x_0226=# CREATE TABLE clients(id serial, client_id int);
| |
− | x_0226=# CREATE TABLE others(id serial, client_id int);
| |
− | | |
− | エクスポートしたcsvから不要な列を削除してそれぞれにインポートする
| |
− | x_0226=# \COPY clients(client_id) FROM '/Users/jq/3tep_gomi/clients_1.csv' WITH CSV DELIMITER ',';
| |
− | x_0226=# \COPY others(client_id) FROM '/Users/jq/3tep_gomi/others_1_c.csv' WITH CSV DELIMITER ',';
| |
− | | |
− | EXCEPTを使ってClientsにないOthersのclient_idを拾う
| |
− | x_0226=# SELECT client_id FROM others EXCEPT SELECT client_id FROM clients order by client_id asc;
| |
− | | |
− | 作業用テーブルを作る
| |
− | x_0226=# create table x_others(id serial, user_id int, note_id int, client_id int, name varchar, yomi varchar, nusi boolean, line int, generation varchar, created_at timestamp, updated_at timestamp);
| |
− | | |
− | others_1.csvをインポートする
| |
− | x_0226=# \COPY x_others(user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',';
| |
− | | |
− | ClientsにないOthersのclient_idを含む行を削除する
| |
− | x_0226=# delete from x_others where client_id in (SELECT client_id FROM others EXCEPT SELECT client_id FROM clients order by client_id asc);
| |
− | | |
− | エクスポート
| |
− | x_0226=# \COPY (select user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at from x_others order by client_id asc) TO '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER;
| |
− | | |
− | tep3のOthersにインポートする
| |
− | tep3_development=# \COPY others(user_id, note_id, client_id, name, yomi, nusi, line, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others_1.csv' WITH CSV DELIMITER ',';
| |
− | </pre>
| |
− | | |
− | ==== Lists ====
| |
| * 旧Categoriesのset_id1を寺ごとに抜き出し Listsに入れる | | * 旧Categoriesのset_id1を寺ごとに抜き出し Listsに入れる |
| <pre> | | <pre> |
165行目: |
106行目: |
| ... | | ... |
| </pre> | | </pre> |
− | :- シーケンス編集
| |
− | <pre>
| |
− | シーケンスの最大値確認
| |
− | select max(id) from lists;
| |
− |
| |
− | シーケンスを最大値以上に設定
| |
− | select setval ('lists_id_seq', 128);
| |
− | </pre>
| |
− |
| |
| ==== ListsのidをClientsのlist_idに入れる ==== | | ==== ListsのidをClientsのlist_idに入れる ==== |
| <pre> | | <pre> |
207行目: |
139行目: |
| | | |
| ==== Categories ==== | | ==== Categories ==== |
− | * 旧Categories set_id 2 が主なカテゴリ | + | * とりあえず必要なカテゴリは少ないので手動入力 ひとつ入れると後はTepnote画面上から入力できる |
− | <pre>
| |
− | * エクスポート
| |
− | \COPY (select id, user_id, jiin_id, content, line, created_at, updated_at from categories where jiin_id = 1 and set_id = 2 and content <> '' order by line asc) TO '/Users/jq/3tep_gomi/category_1_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER;
| |
− | ...
| |
− | </pre>
| |
| <pre> | | <pre> |
− | * インポート
| + | INSERT INTO Categories (user_id, note_id, content, line, defa, created_at, updated_at) VALUES (1, 1, '檀家', 1, true, '2022-02-24 07:00:00', '2022-02-24 07:00:00'); |
− | \COPY categories(id, user_id, note_id, content, line, created_at, updated_at) FROM '/Users/jq/3tep_gomi/category_1_1.csv' WITH CSV DELIMITER ',';
| |
− | </pre>
| |
− | :- シーケンス編集 | |
− | <pre>
| |
− | シーケンスの最大値確認
| |
− | select max(id) from categories;
| |
− | | |
− | シーケンスを最大値以上に設定
| |
− | select setval ('categories_id_seq', 128);
| |
| </pre> | | </pre> |
| <pre> | | <pre> |
230行目: |
148行目: |
| 1 | 1 | 1 | 檀家 | 1 | t | 2022-02-24 07:00:00 | 2022-02-24 07:00:00 | | 1 | 1 | 1 | 檀家 | 1 | t | 2022-02-24 07:00:00 | 2022-02-24 07:00:00 |
| </pre> | | </pre> |
− |
| |
− | ==== Client_categories ====
| |
− | *
| |
| <pre> | | <pre> |
− | エクスポート
| |
− | \COPY (select properties.user_id, properties.jiin_id, properties.ie_id, properties.category_id, properties.created_at, properties.updated_at from properties join categories on properties.category_id = categories.id where properties.jiin_id = 1 and categories.set_id = 2 order by ie_id asc, category_id asc) TO '/Users/jq/3tep_gomi/client_category_1_1.csv' WITH CSV DELIMITER ',' FORCE QUOTE * NULL AS '' HEADER;
| |
− |
| |
− | ...
| |
| </pre> | | </pre> |
| <pre> | | <pre> |
− | インポート
| + | </pre> |
− | \COPY client_categories(user_id, note_id, client_id, category_id, created_at, updated_at) FROM '/Users/jq/3tep_gomi/client_category_1_1.csv' WITH CSV DELIMITER ',';
| |
| | | |
− | ...
| + | === インポート === |
− | </pre>
| + | \COPY notes(user_id, name, kind, meeting_time, role, created_at, updated_at) FROM '/Users/jq/3tep_gomi/notes.csv' WITH CSV DELIMITER ','; |
− | <pre>
| |
− | </pre>
| |
− | <pre>
| |
− | </pre>
| |
− | <pre>
| |
− | </pre>
| |
| | | |
− | <pre>
| + | \COPY others(user_id, note_id, client_id, name, yomi, nusi, order1, order2, generation, created_at, updated_at) FROM '/Users/jq/3tep_gomi/others.csv' WITH CSV DELIMITER ','; |
− | </pre>
| |
− | <pre>
| |
− | </pre>
| |
− | <pre>
| |
− | </pre>
| |