Comments (4)
Additionally, schema.drop( "table" ) does not work consistently. Changing this to schema.drop( "table", {}, true ) did work.
from cfmigrations.
I need some more information on this before I can work on it. A reproducible example would be best, but it seems like that is part of the problem according to what you wrote above. If you can at least give the conditions and code this is happening with, even if it isn't reproducible 100% of the time, that would be something. I'd like:
- CFML Engine and Version
- Database Type and Version
- JDBC Driver and Version
- All migration files trying to be ran.
- ColdBox Version
- cfmigrations version
Additionally, schema.drop( "table" ) does not work consistently. Changing this to schema.drop( "table", {}, true ) did work.
This is especially bizarre to me since schema.drop( "table", {}, true )
is just putting in the default values.
from cfmigrations.
- Lucee 5.3.5+9
- MSSQL 2019
- net.sourceforge.jtds.jdbc.Driver (maybe I should switch this to the microsoft driver...)
- Coldbox 5.6.2+1148
- cfmigrations (2.0.3)
I'm with you on the bizarre. I ran it repeatedly and it kept skipping the drop, causing errors. When I added true it started working...
And this needs a dropIfExists for columns too, (any drop really), to avoid having to put them in try/catch blocks which may miss other errors.
2020_04_15_092429_addGalleryTable:
component {
function up( SchemaBuilder schema, QueryBuilder query ) {
try{
schema.create( "Galleries", function( Blueprint table ) {
table.increments( "id" );
table.integer( "userID" );
table.string( "subdomain" );
table.string( "galleryName" );
table.string( "about" );
table.timestamp( "createdDate" ).default("getDate()");
} );
} catch (any e) {}
try {
schema.alter( "Images", function( table ) {
table.addColumn( table.integer( "galleryID" ).nullable("true") );
} );
} catch (any e) {}
try {
schema.alter( "Users", function( table ) {
table.addColumn( table.timestamp( "createdDate" ).default("getDate()") );
table.addColumn( table.timestamp( "updatedDate" ).default("getDate()") );
table.addColumn( table.timestamp( "lastLogin" ).default("getDate()") );
} );
} catch (any e) {}
}
function down( SchemaBuilder schema, QueryBuilder query ) {
// schema.alter( "Galleries", function( table ) {
// table.dropConstraint( table.primaryKey() );
// } );
schema.dropIfExists( "Galleries",{}, true );
// dump( pita.toSQL() )
// abort;
schema.alter( "Images", function( table ) {
table.dropColumn( "galleryID" );
} );
schema.alter( "Users", function( table ) {
table.dropConstraint( "df_Users_createdDate" );
table.dropColumn( "createdDate" );
table.dropConstraint( "df_Users_updatedDate" );
table.dropColumn( "updatedDate" );
table.dropConstraint( "df_Users_lastLogin" );
table.dropColumn( "lastLogin" );
} );
// dump("wtf");abort;
}
}
2020_04_16_084055_updateGalleryData
component {
function up( schema, query ) {
userList = query.newQuery().from( "users" )
.orderBy("userID")
.orderby("email")
.get();
lastEmail = "";
currentUserID = 0;
deleteList = [];
for ( row in userList ){
// If a user has multiple accounts currently, we're going to use the first one and delete the rest
// We are sorted by email address so compare the last email with the current one to see if it's a duplicate
if (lastEmail != row.email){
// Fresh - init vars
lastEmail = row.email;
currentUserID = row.userID;
} else {
// Duplicate user. Add this ID to a list to delete when the updates are done
deleteList.append(row.userID);
}
// Insert a new gallery record, returning the new galleryID for use in the next query
// Each new gallery will be created with the currentUserID, AKA the first user account we came across
newGalleryID = query.newQuery().from( "Galleries" )
.returning( "id" )
.insert({
"subdomain" = row.username,
"userID" = currentUserID,
"galleryName" = row.username,
"about" = ""
});
// dump(newGalleryID.query.ID);abort;
// Update the images table, using the galleryID we just created.
// This gallery (new subdomain) belongs to a separate userID currently, though.
// So we use the existing userID to find the right images to attach to the new gallery record.
query.newQuery().from( "Images" )
.where("userID", row.userID)
.update({
"galleryID" = newGalleryID.query.ID
});
}
// Delete the extra user records.
// if (deleteList.len()){
// query.newQuery().from( "Users" )
// .whereIn( "userID", deleteList )
// .delete()
// }
// Clean up old columns
// schema.alter( "Users", function( table ) {
// table.dropColumn( "username" );
// } );
// Must delete constraints before columns.
// schema.alter( "Images", function( table ) {
// table.dropConstraint( "DF_images_userID" );
// } );
// schema.alter( "Images", function( table ) {
// table.dropColumn( "userID" );
// } );
// Users => Galleries => Images
}
function down( schema, query ) {
}
}
2020_04_16_091359_changeIds
component {
function up( schema, query ) {
schema.alter( "users", function( table ) {
table.renameColumn( "userID", table.string( "id" ) );
} );
schema.alter( "images", function( table ) {
table.renameColumn( "imageID", table.string( "id" ) );
} );
schema.alter( "images", function( table ) {
table.renameColumn( "userID", table.string( "oldUser" ) );
} );
}
function down( schema, query ) {
try{
schema.alter( "users", function( table ) {
table.renameColumn( "id", table.string( "userID" ) );
} );
schema.alter( "images", function( table ) {
table.renameColumn( "id", table.string( "imageID" ) );
} );
schema.alter( "images", function( table ) {
table.renameColumn( "oldUser", table.string( "userID" ) );
} );
} catch (any e){}
}
}
from cfmigrations.
In my case, was because multiple migrations having same date in the name:
IE:
2021_04_28_170640_create_contact
2021_04_28_170640_create_post
2021_04_28_170640_create_contact_post
When running migrate down
it tried to drop posts
before contact_posts
(which were not allowed by constraints)
Changing the date part in the migration filename, solved this error for me.
Your library is awesome BTW
from cfmigrations.
Related Issues (20)
- Add transaction around the migration HOT 2
- Multiple datasources HOT 1
- Cannot find migration cfc paths in Windows environment HOT 2
- Add Multi-Tenant Support HOT 5
- implement migratedDate in findAll()
- Add option to skip transactions HOT 4
- testbox jquery issue HOT 1
- CFMigrations: Error displayed on missing grammer
- Add squash support for migrations
- Error with H2 database HOT 1
- cfmigrations runs hundreds of duplicate SQL queries on app init
- cfmigration can check if .env or cfconfig has a datasource already created if it has then use that one HOT 3
- Please change QB to provider HOT 1
- Environment safe settings
- open not working on windows after migration file is created.
- Install command errors with no information
- Missing commas in MigrationService.cfc in forgebox but not Github HOT 2
- ACF11: MigrationsService.cfc throws java.lang.ClassCastException exception. HOT 4
- Cfmigration table detected in all available schemes instead of current database HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cfmigrations.