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

PostgreSQL: sequelize sync hangs within transaction when ENUM field exists #3782

Closed
tornillo opened this Issue May 21, 2015 · 3 comments

Comments

3 participants
@tornillo
Contributor

tornillo commented May 21, 2015

TYPE queries are executed outside of the transaction.

var User = sequelize.define('User', {
    type: Sequelize.ENUM('a', 'b')
});

sequelize.transaction()
.then(function (tx) {
    return sequelize.sync({
        force: true,
        transaction: tx
    })
})
.then(function () {
    tx.commit();
});

SQL log:

Executing (814aa406-47f7-405e-be52-620304464fdc): START TRANSACTION;
Executing (814aa406-47f7-405e-be52-620304464fdc): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Executing (814aa406-47f7-405e-be52-620304464fdc): SET autocommit = 1;
Executing (814aa406-47f7-405e-be52-620304464fdc): DROP TABLE IF EXISTS "Users" CASCADE;
Executing (default): DROP TYPE IF EXISTS "enum_Users_type";
<-- hangs here with "default"
@ns3777k

This comment has been minimized.

Contributor

ns3777k commented Jun 14, 2015

https://github.com/sequelize/sequelize/blob/master/lib/query-interface.js#L221
only logging & raw params are passed to the query method to drop enum. transaction's missing.
i tried to to pass the transaction either and it went ok but then the error popped up while recreating the table:

Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): START TRANSACTION;
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): SET autocommit = 1;
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): DROP TABLE IF EXISTS "test" CASCADE;
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): DROP TYPE IF EXISTS "enum_test_type";
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): DROP TABLE IF EXISTS "test" CASCADE;
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): DROP TYPE IF EXISTS "enum_test_type";
Executing (default): SELECT t.typname enum_name, array_agg(e.enumlabel) enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = 'public'  AND t.typname='enum_test_type'  GROUP BY 1
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): CREATE TABLE IF NOT EXISTS "test" ("id"   SERIAL , "title" TEXT, "rank" INTEGER, "type" "enum_test_type", PRIMARY KEY ("id"));
Executing (b5a9a593-d462-4b4d-8a8c-2cc180325f3e): ROLLBACK;
Unhandled rejection SequelizeDatabaseError: type "enum_test_type" does not exist
    at Query.formatError (/Users/nikita/Desktop/nodejs-test/node_modules/sequelize/lib/dialects/postgres/query.js:420:14)
    at null.<anonymous> (/Users/nikita/Desktop/nodejs-test/node_modules/sequelize/lib/dialects/postgres/query.js:104:19)
    at emit (events.js:95:17)
    at Query.handleError (/Users/nikita/Desktop/nodejs-test/node_modules/pg/lib/query.js:99:8)
    at null.<anonymous> (/Users/nikita/Desktop/nodejs-test/node_modules/pg/lib/client.js:166:26)
    at emit (events.js:95:17)
    at Socket.<anonymous> (/Users/nikita/Desktop/nodejs-test/node_modules/pg/lib/connection.js:109:12)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:765:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:427:10)
    at emitReadable (_stream_readable.js:423:5)
    at readableAddChunk (_stream_readable.js:166:9)
    at Socket.Readable.push (_stream_readable.js:128:10)
    at TCP.onread (net.js:529:21)

Process finished with exit code 0

I'll dig further)

@ns3777k

This comment has been minimized.

Contributor

ns3777k commented Jun 14, 2015

well. i got it working. summary - transaction param's missing in these lines:

https://github.com/sequelize/sequelize/blob/master/lib/query-interface.js#L221
https://github.com/sequelize/sequelize/blob/master/lib/query-interface.js#L122
https://github.com/sequelize/sequelize/blob/master/lib/query-interface.js#L138

can send a PR if it's ok to add transaction param there or the whole option thing.

Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): START TRANSACTION;
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): SET autocommit = 1;
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): DROP TABLE IF EXISTS "test" CASCADE;
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): DROP TYPE IF EXISTS "enum_test_type";
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): DROP TABLE IF EXISTS "test" CASCADE;
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): DROP TYPE IF EXISTS "enum_test_type";
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): SELECT t.typname enum_name, array_agg(e.enumlabel) enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = 'public'  AND t.typname='enum_test_type'  GROUP BY 1
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): DROP TYPE IF EXISTS "enum_test_type"; CREATE TYPE "enum_test_type" AS ENUM('a', 'b');
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): CREATE TABLE IF NOT EXISTS "test" ("id"   SERIAL , "title" TEXT, "rank" INTEGER, "type" "enum_test_type", PRIMARY KEY ("id"));
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' and t.relname = 'test' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;
Executing (23197f11-0786-4ad9-a7db-53e6b402e56d): COMMIT;
@mickhansen

This comment has been minimized.

Contributor

mickhansen commented Jun 15, 2015

Should be fixed by the PR from @ns3777k

@mickhansen mickhansen closed this Jun 15, 2015

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