Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass the requirement to have transactionId database column #1

Open
shamasis opened this issue Mar 25, 2015 · 34 comments
Open

Bypass the requirement to have transactionId database column #1

shamasis opened this issue Mar 25, 2015 · 34 comments

Comments

@shamasis
Copy link
Member

No description provided.

@shamasis
Copy link
Member Author

Have added this to autoTK column - as such making it less visible to end model definition, but still being stored in DB. Need to modify waterline to be able to pass connection information from outermost API down to the adapter.

@lucasmonstrox
Copy link

So, Have another solution?

@shamasis
Copy link
Member Author

I have a solution but that requires some time for me to implement. I have already implemented a pet while adding support for .count. I will see if I can take this up early next month.

@lucasmonstrox
Copy link

I have a big project, I'm using your framework and I cant use on development mode. :(

@shamasis
Copy link
Member Author

Hmm. Can you tell me more accurately when is this happening for you? I mean is there a specific pattern when the transaction is failing?

@lucasmonstrox
Copy link

Transactions isnt working. I use transaction.rollback(); but not work. Just it. :/

@lucasmonstrox
Copy link

the field "transactionId" is not being created in the tables.

@shamasis
Copy link
Member Author

Hmm. That is too generic for me to determine the cause of the problem. So, I'm asking a few basic questions:

  • Do you have autoTK enabled on the models? It is enabled by default?
  • Are you using the transact API correctly

@lucasmonstrox
Copy link

Do you have autoTK enabled on the models? It is enabled by default?
R: I just install your framework, create a config of database, but, nothing work.

Observation: I switched to windows when I was in Linux, it worked smoothly.

@shamasis
Copy link
Member Author

:-o that is a serious problem. Without that field transactions will not work at all.

Can you check whether you are on the latest version of the adapter. I guess it would be 0.8.0? This adapter automatically adds the field to the model unless autoTK is set to false.

One more thing - are you testing this in production or development mode?

@lucasmonstrox
Copy link

My configs.

database: {
adapter: 'sails-mysql-transactions',
host: '127.0.0.1',
user: 'root',
password: '',
database: 'test',
charset: 'utf8',
rollbackTransactionOnError: true,
multipleStatements: true
}

@lucasmonstrox
Copy link

My models dont have anything about autoTk, probably this is automatic, right?

@shamasis
Copy link
Member Author

I'm not sure how the OS would influence transactions. You say that the transactionId column itself is not created in table (hope you've directly checked the MySQL database). If that's the case, you should once try running this in "drop" migrate mode (existing data is deleted in this mode.) and see if the columns get created.

@lucasmonstrox
Copy link

Yes, in development mode I'm using "drop" migrate mode but the column is never created. :'(

@shamasis
Copy link
Member Author

Yes. autoTK is automatic. But sails will not edit your database in production or non-drop migration mode.

@shamasis
Copy link
Member Author

I have no clue what could cause this issue. You mentioned that you got it to work on Windows. So, what are the differences between these two projects?

As of now, I have no clue why the columns are not getting created.

@lucasmonstrox
Copy link

In production mode is working smoothly. But now, I need to create some tests using transactions.

@shamasis
Copy link
Member Author

Let me check the code and see if I've done anything special for non production mode. As far as I can remember there's no code difference. Unless this is a SailsJS bug or issue with default model migration config.

@lucasmonstrox
Copy link

I tried to put the "autoTK: true" in my models and still nothing works.

@lucasmonstrox
Copy link

I dont have sails-mysql installed.

@shamasis
Copy link
Member Author

I don't think I can debug the problem with the information I have. I've tried to reproduce the problem but couldn't. Last option is if you can share a scaled down version of your project which is exhibiting the bug.

@lucasmonstrox
Copy link

What is the minimum version of "sails" for this to work?

@shamasis
Copy link
Member Author

It works with 0.11.1+. We recommend 0.11.5

@lucasmonstrox
Copy link

Have any problem if the scripts/postinstall.sh is not executed?

In windows I just can install using "npm install sails-mysql-transaction --force"

@shamasis
Copy link
Member Author

hmm. It could be a problem. You must have sails installed first and then install this adapter. So, try installing sails and then install this adapter.

@lucasmonstrox
Copy link

Sails is already installed.

@lucasmonstrox
Copy link

{
"name": "csgoall",
"description": "a really cool app",
"private": true,
"version": "1.0.0",
"keywords": [],
"engines": {
"node": "4.1.1",
"npm": "2.14.4"
},
"postinstall": "npm install --unsafe-perm --prefix ./node_modules/sails waterline && npm install --unsafe-perm --prefix ./node_modules/sails lodash",
"dependencies": {
"async": "~0.2.7",
"bcryptjs": "^2.3.0",
"bignumber": "^1.1.0",
"coffee-script": "",
"connect-redis": "1.4.5",
"crypto": "0.0.3",
"deferred": "^0.7.4",
"doctrine": "
",
"ejs": "~0.8.4",
"express": "3.5.1",
"grunt": "0.4.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-coffee": "~0.10.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-cssmin": "~0.9.0",
"grunt-contrib-jst": "~0.6.0",
"grunt-contrib-less": "0.11.1",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-sails-linker": "~0.9.5",
"grunt-sync": "~0.0.4",
"include-all": "~0.1.3",
"js-yaml": "~2.1.0",
"jsdom": "^7.1.0",
"kue": "^0.10.4",
"lodash": "^3.10.1",
"on-finished": "^2.3.0",
"passport": "^0.2.2",
"passport-steam": "^0.1.6",
"phantom": "^0.8.4",
"q": "^1.4.1",
"random-picker": "^0.1.0",
"rc": "~0.5.0",
"redis": "^1.0.0",
"request": "^2.62.0",
"sails": "0.11.2",
"sails-disk": "~0.10.0",
"sails-elastic": "^0.11.3",
"sails-fixtures": "^1.0.8",
"sails-hook-email": "^0.12.1",
"sails-hook-publisher": "^0.2.0",
"sails-hook-schedule": "^0.2.1",
"sails-hook-validation": "^0.2.1",
"sails-mysql-transactions": "^0.8.0",
"sails-validation-messages": "0.0.0",
"sailsjs-cacheman": "^0.1.3",
"schema-inspector": "^1.6.4",
"shortid": "^2.2.4",
"socket.io-redis": "^0.1.4",
"steam-totp": "^1.3.0",
"steam-tradeoffer-manager": "^1.16.4",
"steam-user": "^1.9.5",
"steamcommunity": "^3.18.5",
"steamid": "^0.3.1",
"striptags": "^2.0.4",
"swagger-ui": "^2.1.3",
"trim": "0.0.1",
"underscore": "",
"validator": "^4.2.1",
"waterline": "^0.10.28",
"waterline-elasticsearch": "^0.1.3",
"winston": "^1.0.1"
},
"scripts": {
"debug": "node debug app.js",
"start": "node app.js --NODE_ENV"
},
"main": "app.js",
"repository": {
"type": "git",
"url": ""
},
"author": "Le Luquinhas",
"license": "",
"devDependencies": {
"assert": "^1.3.0",
"chance": "^0.7.5",
"express": "^4.12.4",
"frisby": "^0.8.5",
"jade": "
",
"jshint": "*",
"sails-fixtures": "^1.0.8",
"should": "^6.0.3",
"should-http": "0.0.3",
"supertest": "^1.0.1",
"swagger-express": "^1.0.5",
"winston": "^1.0.0"
}
}

@lucasmonstrox
Copy link

Any problem?

@shamasis
Copy link
Member Author

Yes. The post install script overrides the special waterline injected into sails by sails MySQL transactions.

@lucasmonstrox
Copy link

I do it manually using...

npm remove waterline
npm install node_modules/sails-mysql-transactions/waterline

Based on:

pushd "${MOD_DIR}/sails" > /dev/null;
npm remove waterline;
npm install "${MOD_DIR}/sails-mysql-transactions/waterline";
popd > /dev/null;

Still not working :(

@shamasis
Copy link
Member Author

Hmm. Try putting a console log in the sails MySQL transactions waterline scripts. I have a hunch that some other waterline is being used - either installed in root or installed inside sails.

@lucasmonstrox
Copy link

FIXED!!! You are right!!! Oh god!!!

The problem is, if someone have different version of waterline inside sails, so, cause this error.

So, you can fix it puting this script in postinstall.sh:

npm remove waterline;
npm install "${MOD_DIR}/sails-mysql-transactions/waterline";
npm remove --prefix "${MOD_DIR}/sails" waterline;
npm install --prefix "${MOD_DIR}/sails" "${MOD_DIR}/sails-mysql-transactions/waterline";

@lucasmonstrox
Copy link

Something like this!!! 🎯

@hielfx
Copy link

hielfx commented Aug 1, 2016

Is there any way to avoid inserting a 'transactionId' column in the database? I don't really want to add that column to all of my models in the database, thought I have autoTK: false in the models it still fails because:

Error: [Error (E_UNKNOWN) Encountered an unexpected error] Details:  Error: ER_BAD_FIELD_ERROR: Unknown column 'transactionId' in 'field list'

EDIT: After putting the transactionId column when required and executing on postinstall (inside "scripts" in the package.json) the following command I was able to solve my issue:

"postinstall": "npm remove waterline && npm install \"node_modules/sails-mysql-transactions/waterline\" && npm remove --prefix \"node_modules/sails\" waterline && npm install --prefix \"node_modules/sails\" \"node_modules/sails-mysql-transactions/waterline\" && npm install sails"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants