Csv2sql
No description available
Install / Use
/learn @Gizra/Csv2sqlREADME
CSV to SQL for Drupal
Convert CSV to SQL and create a table in your Drupal installation
CSV are a great way to give a client to enter their data that will be migrated to the site. However, for the migration itself, SQL would be quicker.
Install the drush command by running drush dl csv2sql.
Execute the command: drush csv2sql /PATH/TO/file.csv
Scan a directory.
You have the option to scan a whole directory instead of giving an exact path to a csv file.
Execute the command: drush csv2sql /PATH/TO/directory/
Will create a _raw_file table in the Drupal installation which drush is running
under.
- Each column is created as
varchar 255by default. However it is possible to override it by setting the header in the CSV file. - To prevent the user of MySql reserved words, each column is prefixed with an underscore (e.g.
_order) - The first column is treated as the primary column
- In the SQL a serial
__idcolumn is created - Index can be added to any column by adding
index:TRUEto the column's header, The first column of each table is added to the index by default unless stated otherwise (index:FALSE) in the header, This will make for a faster migration if you need to use any column as key for referencing other entities.
| Unique ID|index:FALSE | Amount|type:int|length:11|default:0| Body|type:text|size:big | User|index:TRUE | | -------------------------- | --------------------------------------------------| ----------------------------------| ----- | | title1 | 3000 | Some long text, that might even have line breaks. | user1 |
The complex column will be translated in the DB to an amount column type
int(11) where NULL value is allowed.
The values that can be passed in the header are the ones that are expected by
db_create_table()
Dump SQL and import
In order to deploy a local copy to a remote server you may need to export the SQL tables, and later import them. Here's a handy bash command to do it - it exports all the tables prefixed with _raw_ into the raws.sql file. The second comamnd simply imports that SQL file to the remote server.
# Export SQL tables into a file.
drush sqlq "SHOW TABLES LIKE '_raw_%';" | awk -v ORS=, '{ print $1 }' | sed 's/,$//' | sed 's/^Tables_in_[^,]*,//' | drush sql-dump > raws.sql
# Replace the drush alias with your own.
`drush @remote-alias sql-connect` < raws.sql
Related Skills
feishu-drive
338.7k|
things-mac
338.7kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
338.7kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
yu-ai-agent
1.9k编程导航 2025 年 AI 开发实战新项目,基于 Spring Boot 3 + Java 21 + Spring AI 构建 AI 恋爱大师应用和 ReAct 模式自主规划智能体YuManus,覆盖 AI 大模型接入、Spring AI 核心特性、Prompt 工程和优化、RAG 检索增强、向量数据库、Tool Calling 工具调用、MCP 模型上下文协议、AI Agent 开发(Manas Java 实现)、Cursor AI 工具等核心知识。用一套教程将程序员必知必会的 AI 技术一网打尽,帮你成为 AI 时代企业的香饽饽,给你的简历和求职大幅增加竞争力。
