Skip to content

Create a Blueprint draft file from your (legacy) MySQL database schema

Notifications You must be signed in to change notification settings

ttomdewit/blueprint-draft-from-mysql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create a Blueprint draft file from a MySQL source

As per Blueprint's README:

Blueprint is an open-source tool for rapidly generating multiple Laravel components from a single, human readable definition.

This add-on will read your existing database schema and create a Blueprint draft file based on said schema. It's ultimate goal is to port existing (legacy) projects to the Laravel framework with as little effort as possible.

Available Column Types

As per the Laravel documentation the following column types are supported.

  • bigIncrements
  • bigInteger
  • binary
  • boolean
  • char
  • date
  • dateTime
  • dateTimeTz Due to limitations it's rendered as dateTime
  • decimal
  • double
  • enum
  • float
  • geometry
  • geometryCollection
  • increments
  • integer
  • ipAddress Rendered as string
  • json
  • jsonb Rendered as json
  • lineString Due to limitations in DBAL it's not supported
  • longText
  • macAddress Rendered as string
  • mediumIncrements
  • mediumInteger
  • mediumText
  • morphs
  • uuidMorphs
  • multiLineString
  • multiPoint
  • multiPolygon
  • nullableMorphs
  • nullableUuidMorphs
  • point
  • polygon
  • set
  • smallIncrements
  • smallInteger
  • string
  • text
  • time
  • timeTz Due to limitations it's rendered as time
  • timestamp
  • timestampTz
  • tinyIncrements Rendered as boolean
  • tinyInteger Rendered as boolean
  • unsignedBigInteger Rendered as biginteger unsigned
  • unsignedDecimal
  • unsignedInteger Rendered as integer unsigned
  • unsignedMediumInteger Rendered as integer unsigned
  • unsignedSmallInteger Rendered as smallinteger unsigned
  • unsignedTinyInteger Rendered as boolean unsigned
  • uuid Rendered as string
  • year Rendered as date

Aliases

  • id See bigIncrements
  • foreignId See unsignedBigInteger
  • nullableTimestamps See timestamp
  • timestamps See timestamps
  • timestampsTz See timestamp
  • softDeletes See timestamp
  • softDeletesTz See timestampTz
  • rememberToken

Modifiers

  • autoIncrement
  • charset
  • collation
  • default
  • nullable
  • unsigned
  • useCurrent
  • always
  • unique
  • index
  • primary
  • foreign

Example MySQL input and YAML output

CREATE TABLE `posts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(400) NOT NULL,
  `content` longtext NOT NULL,
  `published_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

This YAML has been taken from Blueprint's README.

models:
  Post:
    title: string:400
    content: longtext
    published_at: nullable timestamp

Example relationships

CREATE TABLE `users` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `posts` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(400) NOT NULL,
  `content` longtext NOT NULL,
  `published_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `comments` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `author_id` bigint(20) unsigned NOT NULL,
  `post_id` bigint(20) unsigned NOT NULL,
  `content` longtext NOT NULL,
  `published_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `comments_author_id_foreign` (`author_id`),
  KEY `comments_post_id_foreign` (`post_id`),
  CONSTRAINT `comments_author_id_foreign` FOREIGN KEY (`author_id`) REFERENCES `users` (`id`),
  CONSTRAINT `comments_post_id_foreign` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
models:
  User:
    name: string
    timestamps
  Post:
    title: string:400
    content: longtext
    published_at: nullable timestamp
  Comment:
    author_id: id:user
    post_id: id
    content: longtext
    published_at: nullable timestamp

About

Create a Blueprint draft file from your (legacy) MySQL database schema

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages