I'm using a model to track my dupermarket purchases. The schema of the table representing items is:
CREATE TABLE "items"
("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"barcode" varchar,
"brand" varchar,
"gendesc" varchar,
"size" float,
"unit_id" integer,
"created_at" datetime NOT NULL,
"updated_at" datetime NOT NULL);
Inclusion of gendesc
(generic description, as a varchar
) was a modeling mistake; I should have made this a foreign key, with the text descriptions in an additional table, as different brands of the same thing are equivalent for some but not all purposes of analysis. So I want to replace the gendesc
column with a gendescs_id
column that is a foreign key for some gedescs
table which would be equivalent to something created thus:
create table gendescs (id integer primary key, gendesc varchar);
select into gendescs(gendesc) distinct gendesc from items;
Is there a sequence of Rails migrations which does something like this?