forge example

$this->seedPath = rtrim($this->seedPath, '\\/') . '/Seeds/';

        if (is_dir($this->seedPath)) {
            throw new InvalidArgumentException('Unable to locate the seeds directory. Please check Config\Database::filesPath');
        }

        $this->config = &$config;

        $db ??= Database::connect($this->DBGroup);

        $this->db    = $db;
        $this->forge = Database::forge($this->DBGroup);
    }

    /** * Gets the Faker Generator instance. * * @deprecated */
    public static function faker(): ?Generator
    {
        if (self::$faker === null && class_exists(Factory::class)) {
            self::$faker = Factory::create();
        }
                $db = Database::connect(null, false);
                $db->connect();

                if (is_file($db->getDatabase()) && $name !== ':memory:') {
                    // @codeCoverageIgnoreStart                     CLI::error('Database creation failed.', 'light_gray', 'red');
                    CLI::newLine();

                    return;
                    // @codeCoverageIgnoreEnd                 }
            } elseif (! Database::forge()->createDatabase($name)) {
                // @codeCoverageIgnoreStart                 CLI::error('Database creation failed.', 'light_gray', 'red');
                CLI::newLine();

                return;
                // @codeCoverageIgnoreEnd             }

            CLI::write("Database \"{$name}\" successfully created.", 'green');
            CLI::newLine();
        } catch (Throwable $e) {
            

    protected $forge;

    /** * Constructor. */
    public function __construct(?Forge $forge = null)
    {
        $this->forge = $forge ?? Database::forge($this->DBGroup ?? config(Database::class)->defaultGroup);

        $this->db = $this->forge->getConnection();
    }

    /** * Returns the database group name this migration uses. */
    public function getDBGroup(): ?string
    {
        return $this->DBGroup;
    }

    
/** * Ensures that we have created our migrations table * in the database. */
    public function ensureTable()
    {
        if ($this->tableChecked || $this->db->tableExists($this->table)) {
            return;
        }

        $forge = Database::forge($this->db);

        $forge->addField([
            'id' => [
                'type'           => 'BIGINT',
                'constraint'     => 20,
                'unsigned'       => true,
                'auto_increment' => true,
            ],
            'version' => [
                'type'       => 'VARCHAR',
                'constraint' => 255,
                
Home | Imprint | This part of the site doesn't use cookies.