How to update text representations of Java maps in PostgreSQL database? - postgresql

We are running Atlassian Bitbucket Server for our developers and we have a backup/restore mechanism that copies the productive configuration onto a test environment. To make everything work well on the test environment, SQL scripts are used to adjust certain settings in the Bitbucket PostgreSQL database (e.g., the base URL, LDAP connection settings, etc.).
Some values in the Bitbucket database seem to be stored as text representations of java.util.Map objects, like the key_value field in this example of the Bitbucket look-and-feel settings (e.g., UI header color):
bitbucket=# select * from plugin_setting where key_name like 'look%';
namespace | key_name | key_value | id
---------------------------+-----------------------------+-------------------------------------+------
bitbucket.global.settings | look-and-feel:COLOR_MAP | #java.util.Map +| 7988
| | customThemePrimaryColour\x0C#abcdef+|
| | customThemeHeaderColour\x0C#9933ff |
In order to better distinguish our test and productive environments, I would like to update the key_value with a whole new map of values, but whatever I tried so far, either had no effect (i.e., the default settings got applied) or even ended up corrupting the database and Bitbucket failed to restart. For example, I tried this, but it simply has no effect:
UPDATE plugin_setting SET key_value='#java.util.Map\ncustomThemeHeaderColour\x0C#abcdef'
WHERE key_name='look-and-feel:COLOR_MAP';
In other words, the UPDATE successfully writes the key_value, but somehow without any line breaks (and the Bitbucket header color remains unchanged after a restart). I also tried to explicitly add a + before the \n line break, but that also had no effect.
It seems that I'm not correctly escaping certain characters or something...

In the meantime, I found the solution. In essence, I just forgot to add the escape String marker E:
-- set the Bitbucket header color to light purple via properties of the look-and-feel plugin
UPDATE plugin_setting SET key_value = E'#java.util.Map\ncustomThemeHeaderColour\x0C#b941ff'
WHERE key_name = 'look-and-feel:COLOR_MAP';
See also: What's the "E" before a Postgres string?

Related

Pulumi import Az StorageAccount without defaults

I'm trying to import an existing azure-native StorageAccount into Pulumi.
I've used the command given in the docs and it works, but it creates a ton of properties with their default values. I'm trying to get rid of them but I can't seem to do it for these ones:
accessTier, allowBlobPublicAccess, allowSharedKeyAccess, enableHttpsTrafficOnly, enableNfsV3, encryption, identity, isHnsEnabled, networkRuleSet
They are all set to their default values, but when I remove them from my C# code Pulumi wants to update them.
I tried to remove them manually from the input in state file, but Pulumi still says it want to remove their <null> value.
What makes this worse is that this is not an in-place update, Pulumi wants to replace the StorageAccount with a new one, which is not ok for me.
To test, I created a new storage account from scratch (without those properties) and everything is just the same (C# code, actual properties of account, Pulumi JSON state) and it works fine... but nope, I can't remove those default from the imported account.
Anyone knows why / how to remove those default imported values?

How can I manually edit the list of recently opened files in VS Code?

I rely heavily on the File: Open Recent… command to open frequently used files, but yesterday my local Google Drive folder got moved to a new location and now I can no longer access any of the files in that folder through the Open Recent panel because the paths don't match.
The fix would be as simple as replacing "/Google Drive/" with "/Google Drive/My Drive/" but I have no idea what file contains the list of files that appears in the recently opened panel.
I'm assuming it's somewhere in ~/Library/Application Support/Code but not sure where.
I was wondering the same thing the other day and found this while searching for a solution, so I took some time to investigate it today.
It's been a a few weeks since you posted, so hopefully this will still be of help to you.
Also, I'm using Windows and I'm not familiar with macOS, but I think it should be easy enough adjust the solution.
Location of settings
Those setting are stored in the following file: %APPDATA%\Code\User\globalStorage\state.vscdb.
The file is an sqlite3 database, which is used as a key-value store.
It has a single table named ItemTable and the relevant key is history.recentlyOpenedPathsList.
The value has the following structure:
{
"entries": [
{
"folderUri": "/path/to/folder",
"label": "...",
"remoteAuthority": "..."
}
]
}
To view the current list, you can run the following command:
sqlite3.exe -readonly "%APPDATA%\Code\User\globalStorage\state.vscdb" "SELECT [value] FROM ItemTable WHERE [key] = 'history.recentlyOpenedPathsList'" | jq ".entries[].label"
Modifying the settings
Specifically, I was interested in changing the way it's displayed (the label), so I'll detail how I did that, but it should be just as easy to update the path.
Here's the Python code I used to make those edits:
import json, sqlite3
# open the db, get the value and parse it
db = sqlite3.connect('C:/Users/<username>/AppData/Roaming/Code/User/globalStorage/state.vscdb')
history_raw = db.execute("SELECT [value] FROM ItemTable WHERE [key] = 'history.recentlyOpenedPathsList'").fetchone()[0]
history = json.loads(history_raw)
# make the changes you'd like
# ...
# stringify and update
history_raw = json.dumps(history)
db.execute(f"UPDATE ItemTable SET [value] = '{history_raw}' WHERE key = 'history.recentlyOpenedPathsList'")
db.commit()
db.close()
Code references
For reference (mostly for my future self), here are the relevant source code areas.
The settings are read here.
The File->Open Recent uses those values as-is (see here).
However when using the Get Started page, the Recents area is populated here. In the Get Started, the label is presented in a slightly different way:
vscode snapshot
The folder name is the link, and the parent folder is the the text beside it.
This is done by the splitName method.
Notes
Before messing around with the settings file, it would be wise to back it up.
I'm not sure how vscode handles and caches the settings, so I think it's best to close all vscode instances before making any changes.
I haven't played around with it too much, so not sure how characters that need to be json-encoded or html-encoded will play out.
Keep in mind that there might be some state saved by other extensions, so if anything weird happens, blame it on that.
For reference, I'm using vscode 1.74.2.
Links
SQLite command-line tools
jq - command-line JSON processor

VS Code Regex search to remove references based on containing text in string

I am attempting to remove all references of a managed package that is going to be uninstalled that spans throughout code base in VS Code
I have using a query to find the field permissions but am wondering if there is a way to search for the reference outside of specifying the exact field name compared to the field containing only "agf" since they are all using it.
Below is the search query:
<fieldPermissions>
<editable>false</editable>
<field>User.agf_Certified_Product_Owner__c</field>
<readable>false</readable>
</fieldPermissions>
In the field, I want to be able to find and delete the 5 associated lines from multiple files if they match "agf" in any combination. Something like the below:
<fieldPermissions>
<editable>false</editable>
<field>agf</field>
<readable>false</readable>
</fieldPermissions>
With any combination of agf in the field, delete all from any file it appears in.
Not an answer but too long for a comment
You don't have to? Profiles/perm sets don't block package's delete. Probably neither do reports.
You'd use your time better by searching for all instances of agf__ (that's with double underscore), should find fields, objects... used in classes, flows, page layouts etc. And search for agf. (with dot) should find all instances where your Apex code calls their classes marked as global.
Alternatively Apex / VF pages with dependencies on package will have it listed in their "meta.xml", for example
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<packageVersions>
<majorNumber>236</majorNumber>
<minorNumber>1</minorNumber>
<namespace>SBQQ</namespace>
</packageVersions>
<status>Active</status>
</ApexClass>
Last but not least - why not just spawn a dev sandbox and attempt the delete there? If it succeeds - great. If not - it'll list the dependencies that blocked the delete. It'll be "the real thing", it'll smite you even if your VSCode project doesn't contain all flows, layouts and thus could lull you into false sense of security. I'd seriously do it in sandbox and then run all tests for good measure, just in case there are some dynamic soql queries that don't count as hard, delete-blocking references.
After delete's done - fetch Profiles / Permsets from this org and the field references will be gone from the xml.

Impossible to delete blank line in generated word with template

I'm currently using m2doc for my Capella project and when I launch the generatio of the docuement with the template that I have created some lines in my tables are empty and they are not deleted.
Example :
test | test | test
| |
file | file | file
I'm currently using Acceleo in my template to retrieve the information in my Capella diagrams. But I don't know how to delete this empty lines in the table which are useless for me.
Example of my code :
{ m:if ports.name.contains('LOC')}
So I need your help to delete this empty lines in my table.
Thank you.
Regards,
Marc
If you insert your table using asTable*() from Sirius services, the table is an instance of the Java type MTable.
You can write a Java service that take a MTable as parameter and check for MRow without any MCell in it. If the MRaw is empty remove it from the table and return the table.

Manipulate PDF via SQL

what I want to do is automatically create PDFs with data from SQL Server 2008 R2. After creation a string shall be added in the first line of the file. This "header" has to be clear text (right click PDF -> edit -> write string in the first line) and therefore can't be added in the pdf-creation process. The codes in the header are beeing used by another job for further processing.
Is there a way to do that via SQL?
Sample data looks like:
Name | Date | Time | Place | Appointment
John Doe |2014-09-15| 11:00 | Narnia | 12:30
I already found ways to create the PDF, using SSRS and subscription or the procedure mentioned here: http://www.sqlservercentral.com/articles/Miscellaneous/creatingapdffromastoredprocedure/1104/
But I wasn't able to write text to first line, just appended it at the end of the file.
Any help is much appreciated!
This can not be done in SQL. There are a few options that I now of that you can look into to see if it will suite your needs.
NOTE : These are not trivial tasks.
Implement your own device renderer, falling back on the default pdf render.
Override the built in pdf renderer to add your custom header.
Use the SSRS web service api and implement the Render method allowing the access to the Pdf as byte[] and further manipulate it to your needs.
The 3rd method would be the most straightforward and ideal method and would work in both web and windows apps.