src/migration.js
function(name, newname) {
				var act = new NobleMachine(function() {
					act.toNext(db.query("SHOW COLUMNS FROM `" + tablename + "`;"));
				});

				act.next(function(result) {
					var sql = "ALTER TABLE `" + tablename + "` CHANGE `" + name + "` `" + newname + "`";

					result.forEach(function(coldatum) {
						if (coldatum['Field'] == name) {
							sql += " " + coldatum['Type'];
							
							if (coldatum['Null'] == 'NO') {
								sql += " NOT NULL";
							}

							if (coldatum['Key'] == 'PRI') {
								sql += " PRIMARY KEY";
							}

							sql += coldatum['Extra'];

							if (coldatum['Default'] != 'NULL') {
								sql += " DEFAULT " + coldatum['Default'];
							}
						}
					});
					sql += ";";

					act.toNext(db.query(sql));
				});

				me.act.next(act);
			}
function(name, newname) {
				var act = new NobleMachine(function() {
					act.toNext(db.query("SHOW COLUMNS FROM `" + tablename + "`;"));
				});

				act.next(function(result) {
					var sql = "ALTER TABLE `" + tablename + "` CHANGE `" + name + "` `" + newname + "`";

					result.forEach(function(coldatum) {
						if (coldatum['Field'] == name) {
							sql += " " + coldatum['Type'];
							
							if (coldatum['Null'] == 'NO') {
								sql += " NOT NULL";
							}

							if (coldatum['Key'] == 'PRI') {
								sql += " PRIMARY KEY";
							}

							sql += coldatum['Extra'];

							if (coldatum['Default'] != 'NULL') {
								sql += " DEFAULT " + coldatum['Default'];
							}
						}
					});
					sql += ";";

					act.toNext(db.query(sql));
				});

				me.act.next(act);
			}
function ( name , newname ) { var act = new NobleMachine ( function ( ) { act . toNext ( db . query ( "SHOW COLUMNS FROM `" + tablename + "`;" ) ) ; } ) ; act . next ( function ( result ) { var sql = "ALTER TABLE `" + tablename + "` CHANGE `" + name + "` `" + newname + "`" ; result . forEach ( function ( coldatum ) { if ( coldatum [ 'Field' ] == name ) { sql += " " + coldatum [ 'Type' ] ; if ( coldatum [ 'Null' ] == 'NO' ) { sql += " NOT NULL" ; } if ( coldatum [ 'Key' ] == 'PRI' ) { sql += " PRIMARY KEY" ; } sql += coldatum [ 'Extra' ] ; if ( coldatum [ 'Default' ] != 'NULL' ) { sql += " DEFAULT " + coldatum [ 'Default' ] ; } } } ) ; sql += ";" ; act . toNext ( db . query ( sql ) ) ; } ) ; me . act . next ( act ) ; }
There doesn't seem to be a proper RENAME COLUMN statement in MySQL. As such, it is necessary to use CHANGE after extracting the current column definition.
There doesn t seem to be a proper RENAME COLUMN statement in MySQL . As such it is necessary to use CHANGE after extracting the current column definition .