|
39 | 39 | "from fastcore.xtras import dataclass_src\n", |
40 | 40 | "from itertools import starmap\n", |
41 | 41 | "\n", |
42 | | - "import sqlalchemy as sa, subprocess" |
| 42 | + "import sqlparse, sqlalchemy as sa, subprocess" |
43 | 43 | ] |
44 | 44 | }, |
45 | 45 | { |
|
2675 | 2675 | { |
2676 | 2676 | "data": { |
2677 | 2677 | "text/plain": [ |
2678 | | - "[(1, Path('migrations/1-add_priority_to_todo.sql'))]" |
| 2678 | + "[(1, Path('migrations/1-add_priority_and_due_date_to_todo.sql'))]" |
2679 | 2679 | ] |
2680 | 2680 | }, |
2681 | 2681 | "execution_count": null, |
|
2702 | 2702 | " cver = self.version\n", |
2703 | 2703 | " for v, p in _get_migrations(mdir)[self.version:]:\n", |
2704 | 2704 | " try:\n", |
2705 | | - " if p.suffix == '.sql': self.execute(sa.text(p.read_text()))\n", |
| 2705 | + " if p.suffix == '.sql':\n", |
| 2706 | + " for stmt in filter(str.strip, sqlparse.split(p.read_text())): self.execute(sa.text(stmt))\n", |
2706 | 2707 | " elif p.suffix == '.py':\n", |
2707 | 2708 | " subprocess.run([sys.executable, p, self.conn_str], check=True)\n", |
2708 | 2709 | " self.version = v\n", |
|
2739 | 2740 | "name": "stdout", |
2740 | 2741 | "output_type": "stream", |
2741 | 2742 | "text": [ |
2742 | | - "Applied migration 1: 1-add_priority_to_todo.sql\n" |
| 2743 | + "Applied migration 1: 1-add_priority_and_due_date_to_todo.sql\n" |
2743 | 2744 | ] |
2744 | 2745 | } |
2745 | 2746 | ], |
2746 | 2747 | "source": [ |
2747 | 2748 | "db.migrate(mdir)\n", |
2748 | 2749 | "test_eq(db.version, 1)\n", |
2749 | | - "assert 'priority' in db.t.todo.c" |
| 2750 | + "assert 'priority' in db.t.todo.c\n", |
| 2751 | + "assert 'due_date' in db.t.todo.c" |
2750 | 2752 | ] |
2751 | 2753 | }, |
2752 | 2754 | { |
|
2758 | 2760 | { |
2759 | 2761 | "data": { |
2760 | 2762 | "text/plain": [ |
2761 | | - "[Todo(title='get it done', name='rlt', id=2, done=False, details='', priority=0),\n", |
2762 | | - " Todo(title='get it done', name='rlt', id=4, done=False, details='', priority=0)]" |
| 2763 | + "[Todo(title='get it done', name='rlt', id=2, done=False, details='', priority=0, due_date=None),\n", |
| 2764 | + " Todo(title='get it done', name='rlt', id=4, done=False, details='', priority=0, due_date=None)]" |
2763 | 2765 | ] |
2764 | 2766 | }, |
2765 | 2767 | "execution_count": null, |
|
2842 | 2844 | { |
2843 | 2845 | "data": { |
2844 | 2846 | "text/plain": [ |
2845 | | - "'user todo pending_todos'" |
| 2847 | + "'_meta todo user'" |
2846 | 2848 | ] |
2847 | 2849 | }, |
2848 | 2850 | "execution_count": null, |
|
2873 | 2875 | { |
2874 | 2876 | "data": { |
2875 | 2877 | "text/plain": [ |
2876 | | - "[Column('title', String(), table=<todo>),\n", |
2877 | | - " Column('name', String(), table=<todo>),\n", |
2878 | | - " Column('id', Integer(), table=<todo>, primary_key=True),\n", |
2879 | | - " Column('done', Boolean(), table=<todo>),\n", |
2880 | | - " Column('details', String(), table=<todo>)]" |
| 2878 | + "[Column('title', VARCHAR(), table=<todo>),\n", |
| 2879 | + " Column('name', VARCHAR(), table=<todo>),\n", |
| 2880 | + " Column('id', INTEGER(), table=<todo>, primary_key=True),\n", |
| 2881 | + " Column('done', BOOLEAN(), table=<todo>),\n", |
| 2882 | + " Column('details', VARCHAR(), table=<todo>),\n", |
| 2883 | + " Column('priority', INTEGER(), table=<todo>, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object>, for_update=False)),\n", |
| 2884 | + " Column('due_date', TEXT(), table=<todo>)]" |
2881 | 2885 | ] |
2882 | 2886 | }, |
2883 | 2887 | "execution_count": null, |
|
3018 | 3022 | "name": "stdout", |
3019 | 3023 | "output_type": "stream", |
3020 | 3024 | "text": [ |
3021 | | - "SELECT todo.title, todo.name, todo.id, todo.done, todo.details \n", |
| 3025 | + "SELECT todo.title, todo.name, todo.id, todo.done, todo.details, todo.priority, todo.due_date \n", |
3022 | 3026 | "FROM todo \n", |
3023 | 3027 | "WHERE (todo.title LIKE :title_1 || '%')\n", |
3024 | 3028 | " LIMIT :param_1\n" |
|
0 commit comments