Пример #1
0
 public function updateTable($table_id)
 {
     /** @var DbTable $table */
     $table = DbTable::find($table_id);
     if (empty($table)) {
         return [];
     }
     $table->update(['description' => Request::input('description')]);
     return $table;
 }
Пример #2
0
 public function syncTables()
 {
     $tableSql = "select table_name from (select t.table_schema as db_name,   \nt.table_name,   \n(case when t.table_type = 'BASE TABLE' then 'table' \nwhen t.table_type = 'VIEW' then 'view'  \nelse t.table_type   \nend) as table_type, \nc.column_name,  \nc.column_type,  \nc.column_default,   \nc.column_key,   \nc.is_nullable,  \nc.extra,    \nc.column_comment    \nfrom information_schema.tables as t \ninner join information_schema.columns as c  \non t.table_name = c.table_name  \nand t.table_schema = c.table_schema \nwhere t.table_type in('base table', 'view') \nand t.table_schema = '{$this->dbName}'  \norder by t.table_schema, t.table_name, c.ordinal_position) as all_columns group by table_name";
     $tableNames = array_pluck((array) DB::select($tableSql), 'table_name');
     $this->info("共有" . count($tableNames) . "张表, 将同步表信息");
     $bar = $this->output->createProgressBar(count($tableNames));
     foreach ($tableNames as $tableName) {
         $tableBuilder = DbTable::withTrashed()->where('name', $tableName);
         if ($tableBuilder->exists()) {
             $table = $tableBuilder->first();
             if ($table->trashed()) {
                 $table->restore();
             }
         } else {
             DbTable::create(['name' => $tableName]);
         }
         $bar->advance();
     }
     DbTable::whereNotIn('name', $tableNames)->delete();
     $bar->finish();
     return DbTable::all();
 }