GithubHelp home page GithubHelp logo

Comments (21)

Toflar avatar Toflar commented on July 22, 2024

I don't think that migration should take place automatically every time you update or install bundles. Migration is something that should actively be monitored by the administrator and thus also be executed manually.

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

A composer script handler certainly feels wrong. We should use Doctrine migrations anyway, but I'm not sure if that can easily be bundled in a library.

from installation-bundle.

bytehead avatar bytehead commented on July 22, 2024

I vote also against automatic database updates.

from installation-bundle.

leofeyer avatar leofeyer commented on July 22, 2024

It seems you all got the ticket wrong. I am not talking about schema updates, which should definitely not be automated. I am talking about the version updates (see the classes I have listed above); and those have been executed automatically in the install tool ever since. 😄

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

I'm very well aware of that. Still a composer script feels wrong, also because it would not be executed on deployment in most cases.

from installation-bundle.

ausi avatar ausi commented on July 22, 2024

I also wouldn’t expect a composer install or update to change my database. It may be better to print a warning on post-update-cmd if the database is out of date.

from installation-bundle.

fritzmg avatar fritzmg commented on July 22, 2024

@aschempp why not, aren't you typically executing composer install after deployment?

from installation-bundle.

ausi avatar ausi commented on July 22, 2024

@fritzmg depends on the deployment. You can also package your application with all vendor files and push it to the server(s).

from installation-bundle.

fritzmg avatar fritzmg commented on July 22, 2024

True, but then you need to update the database some other way anyway. e.g. By executing the install tool (I am assuming that functionality will still be present?)

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

@fritzmg currently I am, but @leofeyer recommended post-update-cmd which does not run on install. But your last comment says it all: there must be other ways to run that anyway.

from installation-bundle.

leofeyer avatar leofeyer commented on July 22, 2024

there must be other ways to run that anyway

Yes, app/console contao:run-version-updates.

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

Yeah, not sure about that…

from installation-bundle.

fritzmg avatar fritzmg commented on July 22, 2024

If that's the only way, then deployments without accessing the console will not be possible anymore. At least not without deploying the complete (updated) database as well.

from installation-bundle.

leofeyer avatar leofeyer commented on July 22, 2024

@aschempp So how do you run the version updates without opening the install tool after every deploy?

from installation-bundle.

discordier avatar discordier commented on July 22, 2024

I would keep the current behaviour of manually starting the migration via both ways.

  • accessing the install tool
  • executing app/console contao:run-version-updates

Performing it automatically in post update feels wrong to me.

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

from installation-bundle.

discordier avatar discordier commented on July 22, 2024

By running bin/console doctrine:schema:update ...
or when having orm and migrations bin/console app/console doctrine:migrations:migrate ...
We are, once again, in a special position as we do not define final entities in our application but are merely combining them "on the fly" due to our extension support. Therefore the approach of other projects does not really relate here.

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

That would only update the schema, but not the database content. I'm pretty sure there are migrations for existing data in any of the big Symfony projects (http://symfony.com/en/projects).

from installation-bundle.

discordier avatar discordier commented on July 22, 2024

@aschempp Sorry but your previous statement is not true, it will migrate what you tell it to migrate, that is what the preUp, postUp, 'preDown' postDown functions are for.

Pseudo code translation of src/Database/Version330Update.php

namespace Contao\CoreBundleBundle\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;

/**
 * Bump contao database to 3.3.0
 */
class Version330Update extends AbstractMigration

    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->abortIf(
            $this->connection->getDatabasePlatform()->getName() != 'mysql',
            'Migration can only be executed safely on \'mysql\'.'
        );

        $this->abortIf(
            !$this->connection->getSchemaManager()->tablesExist('tl_layout'),
            'Table tl_layout not present.'
        );
        $columns = $schemaManager->listTableColumns('tl_layout');
        $this->abortIf(isset($columns['viewport']), 'column viewport already present.');
    }

    /**
     * @param Schema $schema
     */
    public function postUp(Schema $schema) {
        $statement = $this->connection->query("SELECT id, framework FROM tl_layout WHERE framework!=''");
        while (false !== ($layout = $statement->fetch(\PDO::FETCH_OBJ))) {
            $framework = '';
            $tmp = \StringUtil::deserialize($layout->framework);
            if (!empty($tmp) && is_array($tmp)) {
                if (false !== ($key = array_search('layout.css', $tmp))) {
                    array_insert($tmp, $key + 1, 'responsive.css');
                }
                $framework = serialize(array_values(array_unique($tmp)));
            }
            $stmt = $this->connection->prepare('UPDATE tl_layout SET framework=:framework WHERE id=:id');
            $stmt->execute([':framework' => $framework, ':id' => $layout->id]);
        }
        // Add the "viewport" field
        $this->connection->query("ALTER TABLE `tl_layout` ADD `viewport` varchar(255) NOT NULL default ''");
    }

// TODO: implement down() and preDown() for going a version back.
?>

from installation-bundle.

aschempp avatar aschempp commented on July 22, 2024

Yeah that is possible, I'm just not sure if it's supposed to be for that. There's also Doctrine Fixtures thought that might be the right thing for website templates.

from installation-bundle.

discordier avatar discordier commented on July 22, 2024

For templates (in other words: dummy data) you are right, fixtures are the way to go.
However, the migrations are exactly for upgrading (and downgrading) a database in terms of versioning.

from installation-bundle.

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.