Giter VIP home page Giter VIP logo

fk-adder's People

Contributors

ajcastro avatar monrealryan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

monrealryan

fk-adder's Issues

Create a json file containing data needed to drop a foreign key

For example we are developing a blog app. The tables involved are users, tags and posts tables.
Migration Files:
20180101_create_users_table

$table->increments('id');
$table->string('name');

20180101_create_tags_table

$table->increments('id');
$table->string('name');

20180101_create_posts_table

  $table->increments('id');
  Fk::make($table)->add('user_id');
  Fk::make($table)->add('tag_id');
  $table->string('title');
  $table->string('body');

This should generate a json of data that is needed when deleting the foreign key.
Those json files will be saved in directory database/foreign_keys/ and the json filename would be the migration_file_name.json.
So when we run the above migration it will create a file database/foreign_keys/20180101_create_posts_table.json. One json file per migration file. Only 20180101_create_posts_table.json is created because it is the only migration file that calls Fk::make().

The data needed to drop a foreign key is the:

  • table
  • foreign key name.
    Sample Dropping of foreign key :
Schema::table('posts', function ($table) {
  $table->dropForeignKey('the_foreign_key_name');
});

Sample json file format:

[{
"table" : "posts",
"foreign_key_names: ["posts_user_id_foreign_key", "posts_tag_id_foreign_key"]
}]

It is an array of objects, because it can be possible that one migration file can involve many tables.

The code will be placed in the Fk::migrate() method.

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.