Alembic, SQLAlchemy and multiple "apps" inside a project - sqlalchemy

Coming to SQLAlchemy from the world of Django, I would like to have a project split into several apps, where models and views are bunched together according to their purpose.
For example, I am writing a planner app, I would like to have Users and Plans to live in separate apps inside my project. I want to make sure that if I have to split this project into smaller ones, I would have the least amount of work to do possible.
I also would like to be able to generate and run migrations with one command correspondingly, so that I don't have to reconfigure my CI builds every time I add a model or an "app".
So far what I could come up with in this respect is
project structure:
my_planner
+- users
| +- migrations
| | +- versions
| | | +- 0000_initial.py
| | +- __init__.py
| | +- env.py
| | +- script.py.mako
| +- __init__.py
| +- models.py
+- plans (same structure as users)
alembic.ini:
[alembic]
script_location = alembic/migrations # this doesn't seem to matter
version_locations = users/migrations/versions plans/migrations/options
[users]
script_location = users/migrations
[plans]
script_location = plans/migrations
And then I had to place env.py files into my migrations folders and import the models I want to be included into automatic migrations.
However, when I generate my automatic migrations, I have to specify the exact "apps" for which I generate them and specify a branch.
PYTHONPATH=. alembic --name users revision -m 'initial' --rev-id='0000' --branch-label users --autogenerate
And when I apply the migrations, I have to apply them separately for each of the branches.
Is there a way to do these things in one command correspondingly without writing my own custom scripts? Or is there another approach to managing migrations?

Unfortunately, I've not found an out of the box way to do this. I wrote about the approach we went with here.
The gist of it is;
Create common migration functionality
Add a migrations directory with app specific information to each app(schema, metadata)
Add your relevant app sections to the alembic.ini file, referring to each directory
Use branches starting from the base to track each app's migrations separately

Related

How to structure separation and namespaces in CQRS?

I'm looking for advice on how to structure namespaces in a CQRS structured application.
Currently the command-side and the query-side are in the same namespace in each bounded context, but as complexity is growing, it is starting to create problems.
Currently the structure has the following folders which each contains the implementation:
Application
+ Api
+ Cli
+ Web
Domain
+ Action (Command and Command Handlers in one - we are not using a CommandBus)
+ Event
+ Model
+-- Project
|-- Project.file
|-- ProjectRepository.file
Infrastructure
+ Consumer (Projections and ProcessManagers)
+ EventStore
+ Persistance (Denormalized read side)
+-- Project
|-- SqlProjectRepository.file
Common (Supporting namespace)
The issue is now that the Domain Model currently contains both the entities and event sourced aggregate root which are essentially only part the query-side and command-side, respectively.
There is no overlap in the aggregates of the query-side and command-side.
In a refactoring to a separation, where should the slice be made?
Suggestion 1
A full slice resulting in a query and a command-side which means that even the Application layer has read and write side.
Suggestion 2
A slice which is only made on the Domain layer so that the query side contains the (quite anemic) entities of the read model and the command-side holds events, event sourced aggregate root and more.
Please make a 3rd suggestion, if mine do not apply. Thanks.
This is the approach I take - based on CQRS and DDD, noting that our DDD extends to having a separate solution (.NET - Web APIs for different domain bounded contexts).
Secondly, all our infrastructure code, auth handling, and shared code - is done in a private package manager, which removes some of the mess, of a single solution, we DI it in the StartUp (DI). Also note we use EntityFramework as our DB implementation.
However, given that, here is how I and my team, separate out CQRS and DDD.
+ App
+- Command
+-- Application.Command
+-- Data.Command.EntityFramework
+-- Domain.Command
+- Query
+-- Application.Query
+-- Data.Query.EntityFramework
+-- Domain.Query
+ Build
+- Pipeline
+ Database
+- Data.Database.EntityFramework
+- Data.Database.Model
+ Test
Api (API app)
Cli
Currently the structure has the following folders which each contains the implementation...
That's unfortunate.
You are likely to be happier with the maintenance burden if you arrange your name spaces such that things that change together are closer together. Your FrobMarbleRepository belongs in the frobmarble namespace, not in the repository namespace.
I don't think I agree with Jimmy Bogard's complete analysis here, but the lesson of focusing on features is important
https://jimmybogard.com/vertical-slice-architecture/
If you happen to need to use the same name for two different ideas within a single feature, then you might end up splitting that feature into two or more namespaces; on the other hand, the need to re-use a name might indicate you are actually dealing with more than one feature.

How to attach a project without mixing class declarations in PhpStorm?

I like PhpStorm's ability to attach multiple projects to the current window:
I've noticed, however, that all classes declared in both projects are available in both projects, which can lead to duplicate declarations:
I understand how this can be useful at times, however I'd like to attach projects just to navigate easily between them (I prefer this to switching windows), while keeping them separate as if they were in separate windows.
Is this possible?
Currently IDE does not have "scoped indexing" that may be able to resolve this. Right now you would need to exclude such duplicate files or tell IDE to not to treat them as PHP so they do not get indexed as such.
Your current options:
Use Mark Directory As | Excluded via context menu in Project View panel (or manually via Settings (Preferences on macOS) | Directories) for a folder(s) from additional project.
Mark individual files as Plain Text via context menu in Project View panel. The downside: such "marking" is IDE-wide as far as I know, so the same file path will be excluded in another project as well.
Any other exclusion mechanic that is currently available (e.g. Settings (Preferences on macOS) | Editor | File Types | Ignore files and folders -- global as well and based on file name only and file will be completely ignored from all operations... so not really acceptable for your case).
Consider watching after https://youtrack.jetbrains.com/issue/WI-17646 (star/vote/comment) and related tickets to get notified on any progress.
If they are the same classes, have you thought about making a composer package for them? Would be easier to manage it all I think.

What is the proper way to set modifiable install path in PackageMaker?

First of all, I'm talking about PackageMaker, a GUI application; not packagemaker, a command-line program.
I'm trying to make a install package that has three components, installed in different locations:
XxxxBin.app application, default installed to /Applications;
Xxxx.bundle plugin bundle, default installed to /Library/Audio/Plug-Ins/VST/ (and renamed to Xxxx.vst, which is very easy to be achieved by using post-install script);
some resource files, default installed in /Library/Company/Xxxx_resources/.
And I want to allow users to change target directories of each compnent during installation.
I noticed there are two layers in PackageMaker: choice and package. When you drag an app/bundle/directory into PackageMaker, it will create a new choice and a new package. However, both choice and package layer contains Destination, which greatly confused me. In addition, in Components page for packages that is derived from an app or bundle, there is a check box labelled "Allow Relocation", which introduced further confusion.
I failed to find detailed information on those options. And after many attempts, I'm using the following layout and combination of options, that are very close to my target:
three choices and packages, each contain the app, the bundle, or the directory of resources.
in all choice layers, fill the Destination entry with actual default install paths, and select the "Allow alternate volume" checkbox;
in all package layers, fill the Destination entry with /, and select the "Allow custom location" checkbox;
in all Components page in package layers, deselect all Allow Relocation checkbox.
However, it still has a very weird behavior: the app is copied twice, to both its own directory, and overwriting the directory of the plugin bundle. If you "show content" on the installed bundle, it will look something like this:
/Library/Audio/Plug-Ins/VST/Xxxx.vst
|
+contents
|
+-info.plist: after looking on its content, it is actually the app's plist, not the bundle's
|
+-MacOS
| |
| +-Xxxx: the bundle's dynamic library, which is expected to be here
| |
| +-XxxxBin: the app's executable, which is NOT expected to be here
|
+-Resources
|
+-Xxxx.xml: some config info for the bundle, which is expected to be here
|
+-icon.icns: the app's icon, which is NOT expected to be here
I am quite exhausted on this stuff, but still not reaching my target that looks pretty simple: user-changeable install directory for multiple components. It's really appreciate for someone who can drag me out of this quagmire. Thanks for a lot!
Finally I found the actual cause is not in PackageMaker stuffs, but is inside the bundles being packaged. The bundle identifier of both the app and the plugin is empty. After I assign them with distinct values, everything just work fine.

I need to document a command and its output side-by-side

I'm currently developing a set of shell functions and I want to document its output.
I remember there's a command that generates a basic outline in html (and markdown?) where on the first column you've got the command and it output on the right. A crude example:
ls -a1 | .
| ..
| a_dir/
| a_file
| another file
|
ps | PID TTY TIME CMD
| 2920 pts/2 00:00:00 bash
| 3015 pts/2 00:00:00 ps
I would like to know a program that given a set of commands will generate something similar to the previous example, whether it is HTML, markdown, or anything similar.
One way is to use the script utility
SCRIPT(1) User Commands SCRIPT(1)
NAME
script — make typescript of terminal session
SYNOPSIS
script [-a] [-c command] [-e] [-f] [-q] [-t[=file]] [-V] [-h] [file]
DESCRIPTION
script makes a typescript of everything printed on your terminal. It is
useful for students who need a hardcopy record of an interactive session
as proof of an assignment, as the typescript file can be printed out
later with lpr(1).
There is also a python-utility available, called shelllogger
ShellLogger captures all user interactions with a shell. It is intended to be used for software engineering researchers who are interested in inferring programmer behavior from data that can be captured automatically during a programming session. It is similar to the Unix 'script' program, but provides additional features such as XML output, distinguishing user input from system output and tracking the user's current directory.
https://code.google.com/p/shelllogger/

Flash Builder folder structure + .fla workflow

I built 3 variations of a game for different platforms (i.e. Facebook, mobile etc.) in Flash CS4.
I now have the following structure (5 folders):
Facebook
Mobile
Website
Shared_classes
Shared_assets
In each of the top three folders there is a .fla file.
Every .fla uses assets and classes from the "shared folders" but also platform-unique code.
I would now like to migrate this project to Flash Builder but
1) what is the best approach to stay organized?
2) what is the best .fla file workflow?
Well, that depends... if you ever want to migrate to Flex4 and use Maven2 to automate the build, you might want to organize your project as follows:
project-folder
|- common
| |- CommonModule.fla
| |- src
| |- test
|- platform1
| |- Platform1Module.fla
| |- src
| |- test
|- platform2
| |- Platform2Module.fla
| |- src
| |- test
|- ...
I unfortunately didn't organize it this way, and have recently been clobbered when trying to switch away from Adobe's over-priced IDE that doesn't even support building from the commandline. (How on earth is one supposed to perform integration testing or define pre-/post-commit hooks without commandline builds?)