File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ use std::os;
77use migrate:: Migration ;
88use postgres:: { PostgresTransaction , PostgresResult } ;
99
10+ use cargo_registry:: package:: Package ;
11+
1012fn main ( ) {
1113 let db_config = r2d2:: Config {
1214 pool_size : 1 ,
@@ -137,5 +139,29 @@ fn migrations() -> Vec<Migration> {
137139 DROP DEFAULT", [ ] ) ) ;
138140 Ok ( ( ) )
139141 } , proc( _) Ok ( ( ) ) ) ,
142+ Migration :: add_column( 20140926130044 , "packages" , "max_version" ,
143+ "VARCHAR" ) ,
144+ Migration :: new( 20140926130045 , proc( tx) {
145+ let stmt = try!( tx. prepare( "SELECT * FROM packages" ) ) ;
146+ for row in try!( stmt. query( & [ ] ) ) {
147+ let pkg = Package :: from_row( & row) ;
148+ let versions = pkg. versions( tx) . unwrap( ) ;
149+ let v = versions. iter( ) . max_by( |v| & v. num) . unwrap( ) ;
150+ let max = v. num. to_string( ) ;
151+ try!( tx. execute( "UPDATE packages SET max_version = $1 \
152+ WHERE id = $2",
153+ & [ & max, & pkg. id] ) ) ;
154+ }
155+ Ok ( ( ) )
156+ } , proc( _) Ok ( ( ) ) ) ,
157+ Migration :: new( 20140926130046 , proc( tx) {
158+ try!( tx. execute( "ALTER TABLE versions ALTER COLUMN downloads \
159+ SET NOT NULL", [ ] ) ) ;
160+ Ok ( ( ) )
161+ } , proc( tx) {
162+ try!( tx. execute( "ALTER TABLE versions ALTER COLUMN downloads \
163+ DROP NOT NULL", [ ] ) ) ;
164+ Ok ( ( ) )
165+ } ) ,
140166 ]
141167}
You can’t perform that action at this time.
0 commit comments