差分

Tep3-onk

3,968 バイト追加, 2022年9月18日 (日) 13:56
db:rollback
[[category:memo|{{PAGENAME}}]]
{{Font color}}
== generate ==
% rails generate scaffold Other user:references note:references client:references name:string yomi:string client_name:boolean line:integer memo:text generation:string
 
% rails generate scaffold List user:references note:references content:string line:integer
$ rails generate scaffold Post content:text user:references picture:string
$ rails db:migrate:up VERSION=20200504051127
 
% rails db:migrate:reset
== postgres ==
COPY 3066</nowiki>
=== database heroku_dump table dump ===
ALTER TABLE users RENAME TO users_old;
ALTER TABLE clients RENAME TO clients_old;
 
<nowiki>=# select count(*) from clients_old ;
count
-------
5067
(1 row)</nowiki>
% pg_dump --username=jq --table jq_clients clients_old heroku_dump > old_otherclients_old.sql
<nowiki>% psql --username=jq tep5_development < old_otherclients_old.sql
SET
SET
SET
SET
CREATE TABLEERROR: relation "clients_old" already exists
ALTER TABLE
ERROR: relation "clients_id_seq" already existsALTER TABLEALTER SEQUENCEALTER TABLECOPY 30665067 setval -------- 5351(1 row) ERROR: relation "clients_pkey" already existsERROR: relation "index_clients_on_jiin_id" already existsERROR: relation "index_clients_on_user_id" already existsERROR: relation "index_clients_on_user_id_and_jiin_id_and_name" already existsERROR: relation "index_clients_on_yomi_and_ie_id" already existsERROR: there is no unique constraint matching given keys for referenced table "users_old"ERROR: constraint "fk_rails_de6906508b" for relation "clients_old" already exists</nowiki>
=== ie_id 重複修正 ===
2167 | 2
</nowiki>
 
ie_idを変更する
=# update clients_old SET ie_id = ie_id + 20000 where jiin_id = 2;
------
=# update clients_old SET ie_id = ie_id + 40000 where jiin_id = 4;
=# select * from clients_old where ie_id = 2090;
=# update clients_old set ie_id = 6000 where ie_id = 2090 and jiin_id > 1;
 
== 親テーブルie_id 子テーブルie_id 差分削除 ==
% diff aa_clients_id_ie_id.csv bb_clients_old_ie_id.csv > diff.csv
=== insert ===
where
nusi = true;
INSERT 0 1293
</nowiki>
id, name, yomi, ie_id, nusi, user_id, jiin_id, created_at, updated_at, memo, each_order, generation
from
jq_clientsclients_old;INSERT 0 4747</nowiki>
=== insert エラー ===
% rails db:migrate:up VERSION=
 
{{font color||yellow|後で本番環境も変更}}
 
不要
=# delete from clients_old where id in (4028,3911,3912,2998,3007,4359);
 
主重複
<nowiki> ie_id | count
-------+-------
2282 | 2
3703 | 2
(2 rows)
 
=# update clients_old set nusi = false where id = 1346;
 
=# update clients_old set nusi = false where id = 3703;</nowiki>
 
== {{font color||yellow|移動本番でも}} ==
update clients_old set nusi = true where id = 523;
 
delete from clients_old where id = 845;
 
<nowiki>update clients_old set ie_id = 1264 where id = 515;
update clients_old set ie_id = 1264 where id = 1463;
update clients_old set nusi = false where id = 515;</nowiki>
 
delete from clients_old where id = 217;
update clients_old set nusi = false where id = 218;
update clients_old set ie_id = 204 where id = 218;
 
delete from clients_old where id = 811;
 
update clients_old set nusi = true where id = 1792;
 
delete from clients_old where id = 810;
 
delete from clients_old where ie_id = 22653;
 
<nowiki>delete from clients_old where ie_id = 22653;
DELETE 3
tep5_development=# insert into others
(
id, name, yomi, client_id, client_name, user_id, note_id, created_at, updated_at, memo, line, generation
)
select
id, name, yomi, ie_id, nusi, user_id, jiin_id, created_at, updated_at, memo, each_order, generation
from
clients_old;
INSERT 0 4747</nowiki>
=== 指定行を作る ===
;
UPDATE 3066</nowiki>
 
=== 作業テーブル削除 ===
<nowiki>tep5_development=# drop table clients_old ;
DROP TABLE
tep5_development=# drop table jq_clients ;
DROP TABLE
tep5_development=# drop table users_old ;
DROP TABLE</nowiki>
== ローカル ==
== 同期 ==
% rsync -r ~/rails_app_tepnote/4tep/ host:/home/tep/
除外するファイルをまとめる
<nowiki>exclude-file.txt
$ bundle install --without test development
{{font color||yellow|database.yml username:などを確認する (2箇所)}} {{font color||yellow|migrationファイルがダブったときは削除}}  $ rails db:migrate:status RAILS_ENV=production
$ rails db:create RAILS_ENV=production
または
$ rails db:reset RAILS_ENV=production
または
$ rails db:drop RAILS_ENV=production
または
=# drop database mydb;
エラーのとき
daisyuiをインストール
$ yarn add daisyui
 
== 参考 ==
<nowiki>=# delete from clients_old where ie_id in (21,
22,
23,
24,
26,
27,
30,
32,
33,
34,
35,
36,
39,
41,
43,
44,
45,
46,
48,
49,
51,
52,
53,
56,
57,
62,
63,
64,
66,
67,
68,
69,
71,
73,
78,
79,
80,
82,
87,
90,
92,
93,
94,
95,
96,
97,
98,
99,
100,
101,
102,
104,
105,
106,
108,
109,
110,
111,
113,
115,
116,
117,
118,
121,
122,
123,
124,
126,
127,
128,
129,
131,
132,
133,
135,
136,
138,
139,
140,
141,
144,
145,
147,
148,
150,
151,
152,
153,
157,
158,
159,
161,
162,
166,
170,
171,
173,
174,
176,
177,
179,
180,
182,
183,
184,
185,
186,
188,
189,
190,
191,
192,
194,
197,
199,
201,
202,
205,
222,
228,
230,
231,
232,
249,
264,
272,
310,
355,
372,
373,
375,
404,
461,
472,
473,
490,
491,
531,
550,
561,
590,
649,
673,
674,
676,
679,
683,
686,
689,
691,
694,
701,
741,
754,
800,
802,
804,
805,
808,
814,
815,
821,
848,
872,
875,
876,
921,
923,
936,
953,
972,
993,
998,
1009,
1010,
1013,
2072,
5158,
6053)
DELETE 307</nowiki>