66#
77# Companies table is completed by four companies:
88#
9+ # create table companies (
10+ # id serial not null primary key,
11+ # created_at timestamp not null default now(),
12+ # updated_at timestamp,
13+ # name text null
14+ # );
15+ #
16+ # insert into companies (created_at,id,name) values
17+ # ('2012-03-13 13:26:52.184347',1,'Fluent Mobile, inc.'),
18+ # ('2012-03-13 13:26:52.184347',2,'Fiksu, inc.'),
19+ # ('2012-03-13 13:26:52.184347',3,'AppExchanger, inc.'),
20+ # ('2012-03-13 13:26:52.184347',4,'FreeMyApps, inc.');
21+ #
922# id | created_at | updated_at | name
1023# ---+----------------------------+------------+---------------------
1124# 1 | 2012-03-11 13:26:52.184347 | | Fluent Mobile, inc.
1528#
1629# Employees table is associated with companies table via key - id:
1730#
31+ # create table employees (
32+ # id serial not null primary key,
33+ # created_at timestamp not null default now(),
34+ # updated_at timestamp,
35+ # name text not null,
36+ # salary money not null,
37+ # company_id integer not null
38+ # );
39+ #
1840# id | created_at | updated_at | name | salary | company_id
1941# ----+------------+------------+------+--------+------------
2042#
5375#
5476# Employee.create_infrastructure
5577#
56- # Create a partition for each company:
78+ # Create a partitions for each company:
5779#
5880# company_ids = Company.all.map(&:id)
5981# Employee.create_new_partition_tables(company_ids)
6082#
83+ # Each of partition has the same structure as that of the employees table:
84+ #
85+ # id | created_at | updated_at | name | salary | company_id
86+ # ----+------------+------------+------+--------+------------
87+ #
88+ # CREATE TABLE "employees_partitions"."p1" (CHECK (( company_id = 1 ))) INHERITS (employees);
89+ # CREATE UNIQUE INDEX "index_employees_partitions.p1_on_id" ON "employees_partitions"."p1" ("id");
90+ # ALTER TABLE employees_partitions.p1 add foreign key (company_id) references companies(id);
91+ #
92+ # CREATE TABLE "employees_partitions"."p2" (CHECK (( company_id = 2 ))) INHERITS (employees);
93+ # CREATE UNIQUE INDEX "index_employees_partitions.p2_on_id" ON "employees_partitions"."p2" ("id");
94+ # ALTER TABLE employees_partitions.p2 add foreign key (company_id) references companies(id);
95+ #
96+ # CREATE TABLE "employees_partitions"."p3" (CHECK (( company_id = 3 ))) INHERITS (employees);
97+ # CREATE UNIQUE INDEX "index_employees_partitions.p3_on_id" ON "employees_partitions"."p3" ("id");
98+ # ALTER TABLE employees_partitions.p3 add foreign key (company_id) references companies(id);
99+ #
100+ # CREATE TABLE "employees_partitions"."p4" (CHECK (( company_id = 4 ))) INHERITS (employees);
101+ # CREATE UNIQUE INDEX "index_employees_partitions.p4_on_id" ON "employees_partitions"."p4" ("id");
102+ # ALTER TABLE employees_partitions.p4 add foreign key (company_id) references companies(id);
103+ #
61104# Since we have done four records of companies in the table,
62105# we have four partitions:
63106#
66109# employees_partitions.p3
67110# employees_partitions.p4
68111#
69- # Each of partition has the same structure as that of the employees table:
70- #
71- # id | created_at | updated_at | name | salary | company_id
72- # ----+------------+------------+------+--------+------------
73- #
74112# Each of partitions inherits from employees table,
75113# thus a new row will automatically be added to the employees table .
76114#
@@ -205,7 +243,7 @@ class Employee < ByCompanyId
205243
206244Company . create_many ( COMPANIES )
207245
208- # create the employee partitions dependant on the all companies
246+ # create the employees partitions dependant on the all companies
209247
210248company_ids = Company . all . map ( &:id )
211249Employee . create_new_partition_tables ( company_ids )
@@ -216,8 +254,6 @@ class Employee < ByCompanyId
216254# employees_partitions.p3
217255# employees_partitions.p4
218256
219- # now add some employees across the year.
220-
221257employees = [ ]
222258
223259require File . expand_path ( File . dirname ( __FILE__ ) + "/lib/roman" )
0 commit comments