parent
cce0b299b7
commit
fa27d3bf32
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,9 @@
|
||||
class CreateProjectStatuses < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :project_statuses do |t|
|
||||
t.integer :changesets_count
|
||||
t.integer :watchers_count
|
||||
t.integer :project_id
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,11 @@
|
||||
class CreateUserStatuses < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :user_statuses do |t|
|
||||
t.integer :changesets_count
|
||||
t.integer :watchers_count
|
||||
t.integer :user_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,76 @@
|
||||
class StoredStatusProcedure < ActiveRecord::Migration
|
||||
def up
|
||||
#sql = <<- END_OF_SQL_CODE
|
||||
execute "
|
||||
create procedure `sp_user_status_cursor`()
|
||||
begin
|
||||
declare v_uid bigint(22);
|
||||
declare v int(10);
|
||||
declare _done TINYINT(1) default 0;
|
||||
declare cur_user cursor for select user_id, count(*) from changesets where user_id != '' group by user_id;
|
||||
declare continue handler for not found set _done = 1;
|
||||
open cur_user;
|
||||
loop_xxx:loop
|
||||
fetch cur_user into v_uid,v;
|
||||
if _done=1 then
|
||||
leave loop_xxx;
|
||||
end if;
|
||||
begin
|
||||
update user_statuses set changesets_count = v where user_id = v_uid;
|
||||
commit;
|
||||
end;
|
||||
end loop;
|
||||
end;
|
||||
"
|
||||
execute "
|
||||
create event if not exists e_test
|
||||
on schedule every 1 day starts'2013_08_27 01:50:00'
|
||||
on completion preserve
|
||||
do call `sp_user_status_cursor`();
|
||||
"
|
||||
execute "
|
||||
create procedure `sp_project_status_cursor`()
|
||||
begin
|
||||
declare v_uid bigint(22);
|
||||
declare v int(10);
|
||||
declare _done TINYINT(1) default 0;
|
||||
declare cur_user cursor for select project_id,count(*) from (select project_id,repositories.id from repositories inner join changesets where repositories.id = changesets.repository_id)t group by project_id;
|
||||
declare continue handler for not found set _done = 1;
|
||||
open cur_user;
|
||||
loop_xxx:loop
|
||||
fetch cur_user into v_uid,v;
|
||||
if _done=1 then
|
||||
leave loop_xxx;
|
||||
end if;
|
||||
begin
|
||||
update project_statuses set changesets_count = v where project_id = v_uid;
|
||||
commit;
|
||||
end;
|
||||
end loop;
|
||||
end;
|
||||
"
|
||||
execute "
|
||||
create event if not exists e_project_status_test
|
||||
on schedule every 1 day starts'2013_08_27 01:50:00'
|
||||
on completion preserve
|
||||
do call `sp_project_status_cursor`();
|
||||
"
|
||||
execute "
|
||||
set global event_scheduler = on;
|
||||
"
|
||||
end
|
||||
|
||||
def down
|
||||
execute " drop procedure if exists `sp_user_status_cursor`;
|
||||
"
|
||||
execute "
|
||||
drop event if exists e_test;
|
||||
"
|
||||
execute "
|
||||
drop procedure if exists `sp_project_status_cursor`;
|
||||
"
|
||||
execute "
|
||||
drop event if exists e_project_status_test;
|
||||
"
|
||||
end
|
||||
end
|
Loading…
Reference in new issue