Giter Site home page Giter Site logo

Comments (3)

victorstanciu avatar victorstanciu commented on June 18, 2024

Hello Raúl,

Sorry for the delay, I haven't replied to your email until now because I've actually been looking for a solution to your problem that wouldn't involve adding a lot of new functionality to dbv.php.

Shouldn't new revisions update the schema automatically?

They do, but they don't also update your schema files. Your user table still exists on the disk, but now your database only has a users table. You could remove the user.sql file from your schema directory and then export users to users.sql, but that would mean that when a new developer would build the database, he would start with the users table, and the revision that renames the non-existing user table would throw an error.

The solution (at least for now) would be to change your revision script so that it only renames user to users if user exists. Unfortunately, since MySQL doesn't provide a REPLACE IF EXISTS (like it does for DROP IF EXISTS), this needs a small trick. Try replacing your revision script with this:

SELECT COUNT(*)
INTO @exists
FROM information_schema.tables 
WHERE table_schema = '[YOUR DATABASE NAME]'
AND table_name = 'user';

SET @query = IF (@exists > 0, 'RENAME TABLE user TO users', 'SELECT 1');

PREPARE statement FROM @query;

EXECUTE statement;

And then simply remove the user.sql file and export the new users.sql. When a new developer runs the revision script, because they don't actually have the user table, no error will be raised, while those that actually have it will have it renamed.

Please let me know if this works for you :)

from dbv.

victorstanciu avatar victorstanciu commented on June 18, 2024

If anyone else is reading this, any suggestion on how to elegantly circumvent this problem is more than welcome!

from dbv.

pherrymason avatar pherrymason commented on June 18, 2024

It is ok for me, just wondering what is the "official" path to follow and if that scenario was expected.
Thanks for your reply, I will follow this issue.

from dbv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.